Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split function in string
#1
Solved: 11 Years, 4 Months ago
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?
Reply
#2
Solved: 11 Years, 4 Months ago
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
Reply
#3
Solved: 11 Years, 4 Months ago
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
Reply
#4
Solved: 11 Years, 4 Months ago
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.
Reply
#5
Solved: 11 Years, 4 Months ago
@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
Reply
#6
Solved: 11 Years, 4 Months ago
@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?
Reply
#7
Solved: 11 Years, 4 Months ago
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


'---------
Reply
#8
Solved: 11 Years, 4 Months ago
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!!
Reply
#9
Solved: 11 Years, 4 Months ago
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?


Reply
#10
Solved: 11 Years, 4 Months ago
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

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Split Function Chaithra N 0 1,172 12-18-2019, 11:33 AM
Last Post: Chaithra N
  Split a string with multiple delimiters in VBScript nandha 2 8,594 02-10-2018, 06:44 PM
Last Post: nandha
  Calling a function in a Test Script from a function library anupam4j 3 6,131 06-26-2015, 12:31 AM
Last Post: babu123
  Replace a string in a word document with another string rekha.naik 8 15,520 11-14-2013, 12:58 PM
Last Post: pranikgarg
  Split Function diya 2 5,765 11-28-2012, 08:49 PM
Last Post: diya

Forum Jump:


Users browsing this thread: 1 Guest(s)