for example, i have some string
var a = '2,,2,'; var b = ',,,'
how to get only first character,
so i will get
a = '2' b = ','
string s = "abcdefg"; string sB = s[0];
sB = "a"
string a= "abc"; string subString = a.Substring(0,1);
Characters in Strings can be accessed in the same way as arrays.
So for example, to get the first character in a string variable name you use the expression name[0]
name
name[0]
Use the index of the character you want, so: a[0]
For a complete answer:
char getFirstChar(string inString, char defaultChar) { if (string.IsNullOrEmpty(inString)) return defaultChar; return inString[0]; }