当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How do I grab the last string from a index by detecting the comma?

问题描述:

How do I grab the last string from a index by detecting the comma?

Example:

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[0]);

Note: Even if the string does not have a ,(comma), this piece of code will not crash.

Hope it helps!

分享给朋友:
您可能感兴趣的文章:
随机阅读: