tags:

views:

53

answers:

1

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?

+4  A: 

What about:

yourstring.LastIndexOf("foo", 0, currentPosition)                                  
Benjamin Podszun
Well hows about that, by far an easier solution that I was working towards.
CNutt