How do I grab the last string from a index by detecting the comma?
string i = a,b,c,d or i = ab, cd, ef, gh
(the string of i can by dynamic)
So how do I get the last string from the i?? (I need the answer with C# and using the low consume performance ways as possible)
result: a = ad, cd, ef
b = gh
You can use String.Substring along with String.LastIndexOf Method (Char) to get the index of last comma
string last = str.Substring(str.LastIndexOf(',')+1)
You can try this as well:
string strArr = inputStr.Split(','); Array.Reverse(strArr); Debug.Print(strArr);
Note: Even if the string does not have a
,(comma), this piece of code will not crash.
Hope it helps!