Get index of first detected space after a certain index in a string

前端 未结 2 1271
栀梦
栀梦 2021-01-17 13:33

In a string to format (mostly to replace chars with different symbols for rendering test on UI), I have to detect % and then skip all chars util first space from this % char

2条回答
  •  时光取名叫无心
    2021-01-17 14:01

    Following is easiest, and extensible, for your requirement "abcd%1$s efgh %2$d ijkl in this string I have to skip this %1$s & %2$d which are some sort of formatting placeholders."

    string[] placeHolders = new string[] {"%1$s", "%2$d"};
    string[] splits = "abcd%1$s efgh %2$d ijkl".Split(placeHolders, StringSplitOptions.None);
    

    which will provide splits as ["abcd", "efgh", "ijkl"]

提交回复
热议问题