Micro Focus QTP (UFT) Forums
Split function in string - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Split function in string (/Thread-Split-function-in-string)

Pages: 1 2


Split function in string - nidhishnair - 05-22-2011

I am unable to split a string using split function. i want to split jus the characters and not the nos.

var=blah 1234

i tried by:
sp_var=split(var, " ")

but it is somhow not taking <space> as a delimiter. I took the strlen and the no of spaces in between were 4.
when i try

sp_var=split(var,"1")
msgbox sp_var 'blah is displayed

but the nos are dynamic and hence i cannot use those as a delimiter. is there any other way to split this string? could there be any other sp char for 4 spaces? Or are there any other functions that i can use?


RE: Split function in string - sreekanth chilam - 05-22-2011

Hi,

Refer the below example:

Code:
var="blah 1234"
   sp_var=split(var, " ")

   For i=lbound(sp_var) to ubound(sp_var)
       msgbox  sp_var(i)
   Next



RE: Split function in string - lalithome - 05-23-2011

Hi
split works perfectly with " " space i have tried and and ur code is perfect can u tell the error ur getting and what is the result in both split index

lalit


RE: Split function in string - nidhishnair - 05-23-2011

Hi Lalit and sreekanth,

@sreekanth: i tried your code segment as well, but it is returning me the whole string without splitting it.
@Lalit: this is the code segment i tried, the variable nickname=blah 1234, there are 4 characters in between the alphabets and the nos, but it sumhow is not splitting with the delimited <space>, can it be sum other characters in between (like NULL or sumthin)


Code:
sp_var=split(nickname, " ")

   For i=lbound(sp_var) to ubound(sp_var)
       msgbox  sp_var(i)
   Next

i also tried sp_var(0), it shld ve ideally displayed blah, but it did not.


RE: Split function in string - Anand - 05-23-2011

@nidhishnair : it works fine for me too..

Code:
nickname="blah 1234"
sp_var=split(nickname, " ")

For i=lbound(sp_var) to ubound(sp_var)
msgbox sp_var(i)
Next



RE: Split function in string - nidhishnair - 05-23-2011

@anand: it works fine when we assign a string to the variable, but the prob is nickname is being taken from the appln and there are 4 spaces in between the words, it is not taking the delimiter as space. Am not sure what else it can be?


RE: Split function in string - Anand - 05-24-2011

Try to convert the String with the help of Cstr function.
check if the following code works :

' ------------
Code:
converted_nickname=Cstr(nickname)
sp_var=split(converted_nickname, " ")

For i=lbound(sp_var) to ubound(sp_var)
msgbox sp_var(i)
Next


'---------


RE: Split function in string - nidhishnair - 05-24-2011

yea, had tried that as well.. but not success...

i ve resolved it, i printed it using print (<var>) and copied the 4 spaces and used it in a split function.. Big Grin Big Grin

i had tried splitting it earlier with " " but dint work.. But this trick sumhow worked !! Big Grin

Thanks all!!


RE: Split function in string - hamzaz - 04-23-2012

Hi All,

I have a problem, I have the following string


num="123 343 234."

I split the line by using
words=split(num, " ")

for i=lbound(words) to ubound(words)
msgbox(words(i))
next

Now I am getting 123
343
234
.

I want to remove the dot from the end and want to store these values into dynamic array, any suggestion?





RE: Split function in string - Ankesh - 04-23-2012

Replace dot(.) with blank.

For ur reference

Code:
num="123 343 234."

num=Replace(num,".","") ' this will give u the string 123 343 234
Now u can use split and stotre the values in variables.

Regards,
Ankesh