字符位于字符串中当前位置左侧(Position of character to the left of current position in string)

系统教程 行业动态 更新时间:2024-06-14 16:59:22
字符位于字符串中当前位置左侧(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)

更多推荐

本文发布于:2023-04-16 19:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/1ac92713b93d7a0f04b579f40e193810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:当前位置   字符串   字符   Position   character

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!