To comma, or not to comma. That is the question.

# Thread: To comma, or not to comma. That is the question.

1. Senior Member
Join Date
Dec 1969
Posts
204

## To comma, or not to comma. That is the question.

I&#039;m not quite sure how to explain this but I&#039;ll do the best I can. I&#039;ll just explain the scenario...<BR><BR>With the code below, if a user has all four If&#039;s = 1 then the output looks like OT, R, SC, SS<BR><BR>However, suppose the user only has the top two If&#039;s = 1 then the output looks like OT, R, &#060;--Notice the trailing comma? How do I do this type of thing with the commas when they&#039;re needed and no comma if not needed? Thank you lots for the help! :-)<BR><BR>&#060;%<BR>If rs1("usrPropOT") = "1" Then Response.Write "OT, "<BR>If rs1("usrPropR") = "1" Then Response.Write "R, "<BR>If rs1("usrPropSC") = "1" Then Response.Write "SC, "<BR>If rs1("usrPropSS") = "1" Then Response.Write "SS"<BR>%&#062;<BR><BR>:-) again

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## RE: To comma, or not to comma. That is the questio

&#060;%<BR>Dim first<BR> first = True<BR>If rs1("usrPropOT") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "OT"<BR>End If<BR>If rs1("usrPropR") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "R, "<BR>End If<BR>If rs1("usrPropSC") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "SC, "<BR>End If<BR>If rs1("usrPropSS") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "SS"<BR>End If<BR>%&#062;<BR>

3. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Or even...

&#060;% <BR>Dim prop<BR>If rs1("usrPropOT") = "1" Then prop = prop & "OT, " <BR>If rs1("usrPropR") = "1" Then prop = prop & "R, " <BR>If rs1("usrPropSC") = "1" Then prop = prop & "SC, " <BR>If rs1("usrPropSS") = "1" Then prop = prop & "SS, " <BR><BR>If prop &#060;&#062; "" Then<BR> prop = Left(prop, Len(prop) - 2)<BR>End If<BR>Response.Write prop<BR>%&#062; <BR>

4. Senior Member
Join Date
Dec 1969
Posts
2,854

## RE: To comma, or not to comma. That is the questio

&#060;%<BR>If rs1("usrPropOT") = "1" Then strOutput = strOutPut & "OT, "<BR>If rs1("usrPropR") = "1" Then strOutput = strOutPut & "R, "<BR>If rs1("usrPropSC") = "1" Then strOutput = strOutPut & "SC, "<BR>If rs1("usrPropSS") = "1" Then strOutput = strOutPut & "SS"<BR>if left(strOuput, 1) = "," then<BR> strOutput = left(strOutPut, len(strOutput)-1)<BR>end if<BR>Response.Write StrOutput<BR><BR>%&#062;<BR><BR>HTH.<BR>D.

5. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## 2 problems.

It&#039;s a comma+space (need to do - 2).<BR><BR>The last one doesn&#039;t have it, so you&#039;ll take off one of the "S".

6. Senior Member
Join Date
Dec 1969
Posts
2,854

## sorry,

didn&#039;t notice the space after each comma<BR><BR> &#060;% <BR>If rs1("usrPropOT") = "1" Then strOutput = strOutPut & "OT, " <BR>If rs1("usrPropR") = "1" Then strOutput = strOutPut & "R, " <BR>If rs1("usrPropSC") = "1" Then strOutput = strOutPut & "SC, " <BR>If rs1("usrPropSS") = "1" Then strOutput = strOutPut & "SS" <BR>if left(strOuput, 2) = "," then <BR> strOutput = left(strOutPut, len(strOutput)-2) <BR>end if <BR>Response.Write StrOutput <BR><BR>%&#062;

7. Senior Member
Join Date
Dec 1969
Posts
2,854

## RE: 2 problems.

I noticed the comma issue, abit late admittedly, But it won&#039;t take off the S, as its doing, <BR><BR>if left(strOutput, 2) = ", " then<BR> blah blah<BR>end if<BR>

8. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Didn't see that.

You&#039;re right about the not lopping off the "S".

9. Senior Member
Join Date
Dec 1969
Posts
293

## Stripping Function

try this:<BR><BR>
Code:
`<BR>Function NoLeadingTrailing(DataString,TargetChar)<BR>&#039;This function is designed to strip leading and<BR>&#039;  trailing instantiations of TargetChar from<BR>&#039;  DataString.  Note that only 1 instantiation<BR>&#039;  of TargetChar will be taken from the front and<BR>&#039;  back.<BR><BR>    Dim intTemp0,intTemp1<BR>    Dim bolTemp0,bolTemp1<BR>    Dim strTemp0,strTemp1<BR>    Dim strTemp2,strTemp3<BR>    <BR><BR>    strTemp0=DataString<BR><BR>    strTemp0=Replace(strTemp0,TargetChar & TargetChar,TargetChar)    <BR>    if right(strTemp0,1)=TargetChar then<BR>       if len(strTemp0)=1 then<BR>          strTemp0=""<BR>       else      <BR>          strTemp0 = left(strTemp0,len(strTemp0)-1)<BR>       end if<BR>    end if<BR>          <BR>    if left(strTemp0,1)=TargetChar then<BR>       if len(strTemp0)=1 then<BR>          strTemp0=""<BR>       else      <BR>          strTemp0 = mid(strTemp0,2,len(strTemp0))<BR>       end if<BR>    end if <BR>    <BR>    NoLeadingTrailing = strTemp0<BR>end Function<BR>`
<BR>

10. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Same kind of function..

.. 2 more ways:<BR>http://www.27seconds.com/kb/article_view.asp?id=18

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•