[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

split? left? right?

i got rs("x") with lots of numbers divided with comma(,)
*ends with comma too
3434,4343,5456,676556565,65,

how i can print them with space between them?
like this:(and to kill the last comma)
3434 ,4343 ,5456 ,676556565 ,65 ,
0
sasha85
Asked:
sasha85
4 Solutions
 
samic400Commented:
dim mArray
mArray =  Split(rs("x"), ",")

for i=0 to uBound(mArray)
    response.write mArray(i) & " "
next


0
 
Mass Dot NetCommented:
Give this a shot.
<%
Dim strValues, arrValues, iNumberCount, iIndex, sValue
 
'// If the entire string is NULL, convert it to an empty string.
strValues = Trim(rs("x") & "")
 
'// Convert the string into an array of numbers.
arrValues = Split(strValues, ",")
 
iNumberCount = 0
For iIndex = 0 to UBound(arrValues)
	'// Get an individual item in the array, and shave off extra spaces on either side.
	sValue = Trim(arrValues(iIndex))
	
	'// If the value is a number, go ahead and write it out.
	If IsNumeric(sValue) Then
		iNumberCount = iNumberCount + 1
		If (iNumberCount > 1) Then Call Response.Write(", ")
		Call Response.Write(sValue)
	End If
Next
%>

Open in new window

0
 
sasha85Author Commented:
deathtospam ,i understand samic400 solution...
i am kind of lost with yours:

strValues = Trim(rs("x") & "") ?
      sValue = Trim(arrValues(iIndex)) ?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
hieloCommented:
Comma to the left: 3434, 4343, 5456, 676556565, 65
Response.Write Replace( Left( rs("x"),Len(rs("x"))-1 ), ",", ", ")

Comma to the right: 3434 ,4343 ,5456 ,676556565 ,65
Response.Write Replace( Left( rs("x"),Len(rs("x"))-1 ), ",", " ,")
0
 
sasha85Author Commented:
well that's what i'm talking about...replace function is great!:)
hielo, how are you?:)
i understand deathtospam's code now but,
what do you think about deathtospam's code?
i mean what is better-to replace from the begining or processing the rs("x") as deathtospam did...
0
 
hieloCommented:
>>...replace function is great!:)
It sure is

>>hielo, how are you?:)
Super

>>what is better-to replace from the begining or processing the rs("x") as deathtospam did
I find the "Replace" option easier to understand/maintain. If the rs("x") values is "consistent" , processing the other way is kind of an overkill, espcially since it saves the value of Split every time it is called. The way I see it, don't consume extra memory resources if it is not needed.
0
 
sasha85Author Commented:
Replace( Left( rs("x"),Len(rs("x"))-1 ), ",", " ,")
runs on the all rs("x")
or i still need to split and replace every part?
0
 
hieloCommented:
>>or i still need to split and replace every part?
No Splitting necessary. I am assuming rs("x") is some db field. As an example, you would use it as follows:

'assuming you queried the db and the result is in rs
while Not rs.eof
 Response.Write Replace( Left( rs("x"),Len(rs("x"))-1 ), ",", " ,")
rs.moveNext
wend
0
 
sasha85Author Commented:
i just tried that...i got plain page...
my rs("x") was 232,343445,565656,35324,2432,
0
 
hieloCommented:
>>i got plain page
You must be doing something else wrong. I tested that input and it worked fine for me.
<html>
<head>test.html</head>
<body>
<h1>Test throught IE</h1>
<script type="text/vbscript">
Dim rs,result
rs="3434,4343,5456,676556565,65,"
result = Replace( Left( rs,Len(rs)-1 ), ",", ", ")
document.write result
</script>
</body>
</html>

Open in new window

0
 
sasha85Author Commented:
aa ok...my mistake...

thank you!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now