Uipath studio watch panel shows wrong output value

the watch Panel in Uipath Studio is showing a wrong output value after treatment of a string variable.
example
string variable message=“You searched for author Mark Twain. His books can be found in the following stores: Bookland,Classics bookstore.”

Assign activities
authour= message.Split("."c).First.ToString.Substring(message.LastIndexOf(“author”))

v Substring(message.LastIndexOf(“author”)) extracts the Substring that is after “author”;

see the attachment and result

please check why the watch result is not correspending to the expected value

Hi,

try this: message.Substring((message.LastIndexOf(“author”) +6), (message.IndexOf(“.”) - (message.LastIndexOf(“author”) +6)))
Or you can just add +6 at your expression.

LastIndexOf and IndexOf always identify the word “author” from index 0, so you must increment the index (+6). LastIndexOf is if you have more than one word “author” in your sentence, not your case, so no difference.

Try to change the indexOf(".") with LastIndexOf(".") for a better understanding, in this case, you have two points in your sentence, so the result will change :slight_smile:

I hope to clarify that :slightly_smiling_face:

Hi Andreus91,

many thanks for your support, your solution works.
now I know that LastIndexOf and IndexOf identify a word “xxxx” from index 0, so I must increment the index (+[word lenght])

thank you.

1 Like

A pleasure, I had your same doubt at the beginning :stuck_out_tongue:

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