How to get last index with validation?

Total Post:47

Points:331
C#  Winforms 
 1340  View(s)
Ratings:
Rate this:

im doing some experiment on how can i get specific index of string in richTextBox Control .

scenario: I need to find lastIndex of #> but doesnt match with ##>

reason (2) ## will block #

heres what i started for now:

string text = richTextBox1.Text;
int lastIndexOffragment = text.LastIndexOf('#>');

Q: How can i find the real last Index of #> with validation thats its  not ##>

  1. Post:48

    Points:336
    Re: How to get last index with validation?

    I know this is a very ugly method but, i think this will be very easy and not complecated.

    str = "your string";
    
    int iLastIndex = str.Replace("##>", "^^>").LastIndexOf("#>");

    you can use any character instead of ^.

      Modified On Apr-06-2018 04:01:31 AM

Answer