How to take Substring

Ranorex Spy, Recorder, and Studio.
Gobikanna
Posts: 2
Joined: Thu Sep 04, 2014 6:54 am

How to take Substring

Post by Gobikanna » Thu Sep 04, 2014 7:06 am

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to take Substring

Post by krstcs » Thu Sep 04, 2014 2:02 pm

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.
Shortcuts usually aren't...

Gobikanna
Posts: 2
Joined: Thu Sep 04, 2014 6:54 am

Re: How to take Substring

Post by Gobikanna » Fri Sep 05, 2014 5:01 am

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to take Substring

Post by krstcs » Fri Sep 05, 2014 2:01 pm

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.
Shortcuts usually aren't...