Number of last occurance for "find text position" function

Hi,
Can anyone help me?
How i schould get number of last occurance of finded word in “find text position”?
I’m using it in case with telegram web app.

For example, i have many messages in chat, just like:
Start
Start 123
Start word

I want find text position of last massege what include “start”
Number of occurence is not fixed, it’s dynamic, but i need only last occurence. In this example we have 3 times. So, in all i want have an integer=3.

1 Like

Hi @Nikolay_Burykin,

You can use the string function to achieve this:
str = "Start
Start 123
Start word"
lstIndex = str.LastIndexOf("Start");

To print the remaining text after the last “Start”:
str.SubString(lstIndex)

1 Like

@Nikolay_Burykin

you can split the whole string and store it in array. last index of the array will be your required text.Replace the “start” into “” in last array index to get the output.

str=" Start
Start 123
Start word"

split string:
str_array=str.Split({“Start”},stringsplitoptions.None)

1 Like

I think it’s help me in another case, thx.
But in this case it’s return index of last character of word, that we find, not number of occurence.
In this case i want get int=3

i’m not shure, what i understand how get an integer with number of occurence from this array
Can you ask one more example, please?

This will return the text from the strText string considering that you can have some letters in uppercase.
So if your string is “Start 123, start kjkj Start: ok” you will get “Start: ok”

strText.Substring(strText.ToString.ToUpper.LastIndexOf(“START”))

@Nikolay_Burykin

to get the count of array:
arr.count

@Nikolay_Burykin,

Please use regular expression to get the count of occurrences:
Regex.Matches(Str,"Start").Count

Regards,
PD

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.