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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a function and Reg Exp

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I have a function that I want to check the first character from the left and see if it is a comma, if it is a comma I want to make it a space, if it isn't a comma I want to do nothing. How would I check this? Here is my function I don't know how to test firstAndlast to see if the first character from the left is a comma???

Function MyFunction(firstAndlast) As String
Dim retvalue
If firstAndlast="," Then
retvalue=&quot;<font color=#FFFFFF>&nbsp;</font>&quot;
End If
return retvalue
End Function
 
Hi

I don't know if I read your post correctly. I've made you two functions - the first does not use RegExp and the second one does. Both of them return the string, and if the first character is a comma, it will have been replaced by a space

eg &quot;,Hello&quot; -> &quot; Hello&quot;

Hope this helps

Mark

Public Function ReplaceIfFirstComma(ByVal strInput As String) As String
If strInput.Chars(0) = &quot;,&quot;c Then
strInput = Replace(strInput, &quot;,&quot;, &quot; &quot;, 1, 1, CompareMethod.Text)
End If
Return strInput
End Function

Public Function RegExpReplaceIfFirstComma(ByVal strInput As String) As String
Dim RE As New RegularExpressions.Regex(&quot;^,&quot;)
strInput = RE.Replace(strInput, &quot;^,&quot;, &quot; &quot;)
Return strInput
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top