Hi Friends,

Can any one answer to my problem here please ? I need to split a string into substrings like following example.

Romans 3:1,5;Romans 4:1-10(Semicolon between two strings)
Romans 3:1,5,Romans 4:1-10(Comma between two strings)

These two cases are similar,In these two cases also i want to do like following... Here we need to split into two strings like following:

String(0) = Romans 3:1,5
String(1) = Romans 4:1-10

How is it possible ? If you can, thanks in advance

Urs Friend
Venu.K

Hi,

You can use split function as follows

``````str = "Romans 3:1,5;Romans 4:1-10"
arrstr = split(str,";")``````

Hi,

use the following logic to solve this
Suppose your string that user inputs is
str

``````splitstr=""
if InStr(str, ";") <> 0 then
splitstr=";"
elseif InStr(str, ",") <> 0 then
splitstr=","
end if
arrstr = split(str,splitstr)``````

## All 7 Replies

Hi,

You can use split function as follows

``````str = "Romans 3:1,5;Romans 4:1-10"
arrstr = split(str,";")``````

Hi Vivek,

Let me say once again about problem here,

Some times i will give comma(,) and some other times Semicolon(;)...
Example :-
Romans 3:1,5;Romans 4:1-10
Romans 3:1,5,Romans 4:1-10

We dont know that which one used by the user, But we need to give the same o/p in similar two cases ,
Just like
ArrStr(0) = Romans 3:1,5
ArrStr(1) = Romans 4:1-10

I hope U understand the problem here,,,,

so, How can we solve it?

Hi,

You can use split function as follows

``````str = "Romans 3:1,5;Romans 4:1-10"
arrstr = split(str,";")``````

Hi,

use the following logic to solve this
Suppose your string that user inputs is
str

``````splitstr=""
if InStr(str, ";") <> 0 then
splitstr=";"
elseif InStr(str, ",") <> 0 then
splitstr=","
end if
arrstr = split(str,splitstr)``````

Ohh, your string contains both comma and semicolon, in this case the logic that I provided you will fail.

Hi Use Following Code...

``````<%
xstr = Your String which you want
x = 0
' if you think you have more thn 100 values in a string then change the values in bellow line's code
dim xarray(100)

xarray1 = Split(xstr,";")

for i=0 to ubound(xarray1)
if instr(xarray1(i),",") Then
xarray2 = Split(xarray1(i),",")
for p=0 to ubound(xarray2)
xarray(x) = xarray2(p)
x = x + 1
Next
Else
xarray(x) = xarray1(i)
x = x + 1

End If

Next

for i=0 to ubound(xarray)

response.write xarray(i)&"<br>"
Next
%>``````

Regards,
Hemant

Hi Hemant,

Sorry Friend, I am sorry to say that your code is not correct.May be you understand the problem in wrong way... Any way once again sorry....

Here see the problem once again,Semicolon and commas also there in input, I dont want to do splitting every time when it found the comma... There are some restrictions, They are We need to do only when it follows the Characters...Please once again you see the query thay i provided as a first query,You might be understand the problem here....

Once again Thank you for your valuable time...

Keep in touch

Urs Venu.K

Hi Use Following Code...

<%
xstr = Your String which you want
x = 0
' if you think you have more thn 100 values in a string then change the values in bellow line's code
dim xarray(100)

xarray1 = Split(xstr,";")

for i=0 to ubound(xarray1)
if instr(xarray1(i),",") Then
xarray2 = Split(xarray1(i),",")
for p=0 to ubound(xarray2)
xarray(x) = xarray2(p)
x = x + 1
Next
Else
xarray(x) = xarray1(i)
x = x + 1

End If

Next

for i=0 to ubound(xarray)

response.write xarray(i)&"<br>"
Next
%>

Regards,
Hemant

Hi,

an you properly explain your pronblem, as the way you have given the requirement, that will be the solution that you will get.

As per my understanding now, your requirement is " if semicolon is followed by comma then it should split by comma.

if semicolon is followed by semicolon, then it should split by semicolon.

if comma is followed by comma, then it will split by comma.
if comma is followed by semicolon, then it will split by semicolon.

if this is the requirement then you can use the following logic.

``````splitstr=""
if (semi = InStr(str, ";")) <> 0 then
if InStr(semi,str,";") <> 0 then
splitstr=";"
elseif InStr(semi,str,",") <> 0 then
splitstr=","
end if
elseif (semi=InStr(str, ",")) <> 0 then
if InStr(semi,str,";") <> 0 then
splitstr=";"
elseif InStr(semi,str,",") <> 0 then
splitstr=","
end if
end if
arrstr = split(str,splitstr)``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.