Back to contents pageHow to convert between tag ids, tag objects and tag id strings

How to convert between tag ids, tag objects and tag id strings

Summary

This article gives example methods to convert between tag ids, tag objects and tag id strings using the Ubisense .NET API.



Prerequisites

None. You can use this article on its own.



Example material

Save this link to get a zip file of the example material


Guide

Before you start, remember to:

The following examples give definitions for methods to convert between Ubisense.ULocationIntegration.Tag instances, string instances and tag IDs as ulong integers.



1) String to tag ID

Ubisense.ULocationIntegration.Tag.ConvertStringToId is used to get a tag ID from the string written on the tag casing, for example '123-123-123-123':


    // Method to return a tag ID given a string
    public static ulong string2tagid(string _s)
    {
        return Ubisense.ULocationIntegration.Tag.ConvertStringToId(_s);
    }



2) String to tag

You can create a tag from a string by using the tag ID in the Ubisense.ULocationIntegration.Tag constructor:


    // Method to return a tag given a string
    public static Ubisense.ULocationIntegration.Tag string2tag(string _s)
    {
        return new Ubisense.ULocationIntegration.Tag(
            Ubisense.ULocationIntegration.Tag.ConvertStringToId(_s));
    }



3) Tag to tag ID

You can get a tag's ID as a ulong by using the ToString() method on the Ubisense.ULocationIntegration.Tag.Id field and again use Ubisense.ULocationIntegration.Tag.ConvertStringToId:


    // Method to return a tag ID given a tag
    public static ulong tag2tagid(Ubisense.ULocationIntegration.Tag _t)
    {
        return Ubisense.ULocationIntegration.Tag.ConvertStringToId(_t.Id.ToString());
    }



4) Tag ID to string

Ubisense.ULocationIntegration.Tag.ConvertStringToId is used to get a tag ID as a string, with any char as a byte-separator. A hyphen is commonly used so that the string matches that printed on the tag casing. The following example shows how to use this method given a tag ID as a ulong:


    // Method to return a string given a tag ID
    public static string tagid2string(ulong _id)
    {
        return Ubisense.ULocationIntegration.Tag.ConvertIdToString(_id, '-');
    }



5) Tag to string

This example uses the techniques from previous examples to get the tag ID string from a Ubisense.ULocationIntegration.Tag:


    // Method to return a string given a tag
    public static string tag2string(Ubisense.ULocationIntegration.Tag _t)
    {
        return
            Ubisense.ULocationIntegration.Tag.ConvertIdToString(
            Ubisense.ULocationIntegration.Tag.ConvertStringToId(
            _t.Id.ToString()), '-');
    }



6) Tag ID to tag

This example shows how to create a Ubisense.ULocationIntegration.Tag instance given its ID:


    // Method to return a tag given a tag ID
    public static Ubisense.ULocationIntegration.Tag tagid2tag(ulong _id)
    {
        return new Ubisense.ULocationIntegration.Tag(_id);
    }



Back to top