get all characters to right of last dash

前端 未结 9 392
遇见更好的自我
遇见更好的自我 2020-12-07 13:50

I have the following:

string test = \"9586-202-10072\"

How would I get all characters to the right of the final - so 10072. Th

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 14:06

    I created a string extension for this, hope it helps.

    public static string GetStringAfterChar(this string value, char substring)
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                var index = value.LastIndexOf(substring);
                return index > 0 ? value.Substring(index + 1) : value;
            }
    
            return string.Empty;
        }
    

提交回复
热议问题