-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,118
  • 1
  • 18
  • 34

4 Answers4

3
string myString = "HelloWorld";
char myChar = myString[index];
mayabelle
  • 9,496
  • 8
  • 35
  • 59
1

How about

string result = mystring[myindex].ToString();
Nikhil Agrawal
  • 44,717
  • 22
  • 115
  • 201
1

Like an array:

var s = "hello";
var ch = s[0]; // ch == 'h'
Alessandro D'Andria
  • 8,333
  • 2
  • 33
  • 31
0

Treat the string as an array.

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

Writes...

a
Tom Bowers
  • 4,600
  • 2
  • 28
  • 42