-3

Just like the GetAt method of the CString type in C++, whats the equivalent function in c# to get the character at a particular index in a string?

Tyler Durden
  • 1,188
  • 2
  • 19
  • 35

4 Answers4

3
string myString = "HelloWorld";
char myChar = myString[index];
mayabelle
  • 9,804
  • 9
  • 36
  • 59
1

How about

string result = mystring[myindex].ToString();
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
1

Like an array:

var s = "hello";
var ch = s[0]; // ch == 'h'
Alessandro D'Andria
  • 8,663
  • 2
  • 36
  • 32
0

Treat the string as an array.

var testString = "blah";
Console.WriteLine(testString[2]);

Writes...

a
Tom Bowers
  • 4,951
  • 3
  • 30
  • 43