Micro Focus QTP (UFT) Forums

Full Version: Split function in string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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?
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
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
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.
@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
@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?
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


'---------
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!!
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?


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

Pages: 1 2