Indexof method

Hi All,

I have a text in excel example: ABC1 - Testing Testing Testing
What I need is to extract the text ABC (the first three letters)

however when I use the assign activity of value “Variable Text=Variable Text.Substring(Variable Text.IndexOf(” “)+1,4)” I extracted - Te

Do anyone know if the vb expression I entered is correct?

Thanks in advance!



Will extracts you the required substring (first three letters). No need of IndexOf method.


Hi KarthikByggari,

Thanks for the advise. It works like a charm!


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 )
–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”

– 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


Can you please mark the previous post as solution. It helps other community members to find the solution.

Thank you.

Karthik Byggari

1 Like

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