字符位于字符串中当前位置左侧(Position of character to the left of current position in string)
从字符串中的某个任意位置开始,我需要在我的位置左侧找到一个字符的最近位置。 如果我想要执行此操作的权利,我可以使用.IndexOf,但如何做到左侧,我不确定。
我想到的两种方法只是一个递减循环,从我的位置开始,或者将字符串反向并使用正常的.IndexOf
任何人都有更好的方法来实现这个目标?
From some arbitrary position in a string I need to find the closest position of a character to the left of my position. If I was wanting to perform this operation to the right I could just use .IndexOf, but how to do it to the left I am unsure.
The two ways I came up with were just a decrementing loop starting at my position or, putting the string in reverse and using a normal .IndexOf
Anyone else have any better ways of acheiving this?
最满意答案
关于什么:
yourstring.LastIndexOf("foo", 0, currentPosition)What about:
yourstring.LastIndexOf("foo", 0, currentPosition)更多推荐
发布评论