Page 1 of 1

How to take Substring

Posted: Thu Sep 04, 2014 7:06 am
by Gobikanna
Hi all,

I am very new to this forum.
I have captured a text value into a variable, but i have to take substring. Please help me, how to take substring from that variable.

Regards,
GK

Re: How to take Substring

Posted: Thu Sep 04, 2014 2:02 pm
by krstcs
Since Ranorex is built on .NET, you have all of the power of the .NET platform available to you. (You will have to use user-code for this, there is no way to do this with the Ranorex actions currently available.)

There are several ways to get a sub-string from a string, but it depends greatly on what you need to do. If you could provide an example of what the string is and what part you need, we may be able to help more.

Re: How to take Substring

Posted: Fri Sep 05, 2014 5:01 am
by Gobikanna
Hi krstcs,

Thanks for your reply.

Actually i have stored a output value in a variable which is token no.
TokenNum=1000114247 060800

In the above example i have to pass only 060800 only as an input to a field. How to write usercode to get only 060800.

Thanks & Regards,
GK

Re: How to take Substring

Posted: Fri Sep 05, 2014 2:01 pm
by krstcs
You could use string.Split() http://msdn.microsoft.com/en-us/library ... 90%29.aspx

Code: Select all

string newToken = TokenNum.Split(' ')[1];
Split, in this case, needs to know the character you are splitting the line on (' ' - a space, characters in .NET are wrapped with single-quotes). It will return an array of strings for each section of the original string that is split using the character passed in. In this case, you should have 2 sections. Since arrays in .NET (and most other languages) are 0-based indexes, the first element is 0, the second is 1, and so on. So, we want the second part of the split and use the [1] to tell .NET what index to use on the returned array.


You are a developer now, developing Ranorex .NET applications for testing, so you should learn as much as you can about .NET and software development.