Indexof method

Hi @minthodology

Let me tell you first why you got - Te as result
And then will go for the alternative
… Great

So your string is
“ABC1 - Testing Testing Testing”

Usually the substring syntax is
String.substring(starting position, No. Of characters to extract)

So you mentioned
Variable Text.Substring(VariableText.IndexOf(” “)+1,4)
Here the staring position tells us
VariableText.IndexOf(" ") and the indexof usually gives the index position of the character passed as a argument which occurs first in the string and here the character mentioned is a space and the first space occurs at index 4. ( Index starts at 0 )
So
–Variable Text.Substring(4+1,4)
–Variable Text.Substring(5,4)
Now the starting position becomes 5 which is **-**in the string see…
“ABC1 - Testing Testing Testing”
012345

– From there i.e., - we are going to four no of characters like - Te ( here space is also a character )
Thats why we didnt get ABC as required one rather we get - Te

So to get the ABC we can go by two methods
Either. By yours…
Like this with indexof method
Variable Text.Substring(VariableText.IndexOf(”A“),3)

Or by another method without index of method
Variable Text.Substring(0,3)

Thats all you are done
Hope this would help you
Cheers @minthodology

13 Likes