Krishna Mohan
Krishna Mohan

Reputation: 89

how to add dot symbol after nth character of string in c#

how to add a decimal symbol after second character of a string.

sample data = 78383083

desired op = 78.383083

code

  string data = "011F03010A366B04AC07EB";
    string longitude = data.Substring(14, data.Length - 14); //04AC07EB
    string latitude = data.Substring(6, data.Length - 14); //010A366B
    long lat=Convert.ToInt64(longitude, 16);//78383083 
    string latvalue=lat.ToString();
    // string latvalue1=latvalue.Substr(0,2)+":"+latvalue.substr(2);

Upvotes: 3

Views: 5288

Answers (3)

Muhammad Awais
Muhammad Awais

Reputation: 4502

You can try this:

string str = "123456789";

           if (str.Length > 5)
           {
             label1.Text = string.Concat(str.Substring(0, 5), "...");
           }
           else
           {
               label1.Text = str;
           }

Upvotes: -1

Aatish Sai
Aatish Sai

Reputation: 1687

You can use the insert() method in C# to insert character in any position. Remember it is a zero based index.

string final_data = data.Insert(2,".");

You can learn more about here.

Upvotes: 4

Mighty Badaboom
Mighty Badaboom

Reputation: 6155

Keep it simple:

string result = data.Insert(2, ".");

Upvotes: 3

Related Questions