-1

Not Quite what the title suggests, what i need is a way to count a string backwards like

string i = "3027"
i[0] = label1.Text

Result = 7 not 3 is there a way?

not sure if you need my code or not its not really important.

1 Answers1

5

You can reverse the string using a number of approaches including

public static string ReverseString(string s)
{
    char[] arr = s.ToCharArray();
    Array.Reverse(arr);
    return new string(arr);
}

http://www.dotnetperls.com/reverse-string

then access the portion of the reversed string that you are interested in.

Note that you cannot assign to i[0] as shown in your example code because strings are immutable in C# (why). If you want to construct a string a bit at a time, it is often most efficient to use StringBuilder.

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553