Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting problems... 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
This spits out some values like this

test, test, test, test,

but I am trying to remove the last comma and can't get this to work.


For Each x in KeyWordSplit

If KCount = 1 - CountDims(KeyWordSplit) then
sComma = ""
Else
sComma = ", "
End If
Response.write x & sComma
kCount = kCount + 1
Next
 
Hi

tally = 0
For Each x in KeyWordSplit
If tally>0 then
response.write(sComma)
End if
tally = tally + 1
If KCount = 1 - CountDims(KeyWordSplit) then
sComma = ""
Else
sComma = ", "
End If
Response.write x
kCount = kCount + 1
Next

See what we are doing? We are writing the comma at the start of each entry, unless it is the first one. Make sense?

Text manipulations 'R' Us

Derren
[Mediocre talent - spread really thin]
 
Sorry - forgot to strip the superfluous code!

tally = 0
For Each x in KeyWordSplit
If tally>0 then
response.write(", ")
End if
tally = tally + 1
Response.write x
Next

Derren
[Mediocre talent - spread really thin]
 
<%@ language=&quot;vbscript&quot;%>

<%
Option Explicit

dim str, strSplit, i

str = &quot;test1, test2, test3, test4,&quot;

str = left(str, len(str) - 1)

strSplit = split(str)

for i = 0 to ubound(strSplit)
response.write strSplit(i) & &quot;<br>&quot;
next
%>
 
Wouldn't it be easier to write:-

'Loop Thro String
sOutput = &quot;&quot;

For Each x in KeyWordSplit
'Add Comma and Space Delimiter
sOutput = sOutput & x & &quot;, &quot;
Next

'Remove End Comma and Space
sOutput = Left(sOutput, Len(sOutput) - 2)

'Print Out
Response.write sOutput


Codefish


 
sweevo got in before me!

sweevo method is even better.

Codefish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top