获取字符串中某个索引之后的第一个检测到的空间的索引 [英] Get index of first detected space after a certain index in a string
问题描述
在要格式化的字符串中(主要是用不同的符号替换char以在UI上进行渲染测试),我必须检测%,然后从此%char中跳过所有char util的第一个空格,并且必须对其中的所有实例重复此操作字符串.
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 and it has to be repeated for all instances in the string.
例如 abcd%1 $ s efgh%2 $ d ijkl
.在此字符串中,我必须获取%的索引,然后从中找到第一个空格的索引.基本上,我必须跳过此%1 $ s
&%2 $ d
是某种格式的占位符.我希望,我不会在这里提出复杂的内容.
E.g. abcd%1$s efgh %2$d ijkl
.In this string, I have to get index of % and then find index of first space from that. Basically, I have to skip this %1$s
& %2$d
which are some sort of formatting placeholders. I hope, I am not putting it in complex way here.
推荐答案
您可以轻松获得它,只需在第一个百分号前获取索引,然后利用该索引从那里找到第一个空格:
You can get that pretty easily, just grab the index if the first percent sign and then leverage that index to find the first space from there:
var start = myString.IndexOf("%");
var spaceIndex = myString.IndexOf(" ", start)
当然,myString的值是您在问题中表示的字符串.
of course the value of myString is the string you represented in your question.
这篇关于获取字符串中某个索引之后的第一个检测到的空间的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!