Easy way to remove a number at the start of a fiel

# Thread: Easy way to remove a number at the start of a fiel

1. Member
Join Date
Dec 1969
Posts
66

## Easy way to remove a number at the start of a fiel

Hello,<BR><BR> Is there an easy way to remove a random number in the start of all of a remark field? Most of my fields do not have the number or look something like this:<BR><BR>0436201020000BEAUTIFUL BRICK & VINYL 2 1/2 STORY ON AN 18 HOLE CHAMPIONSHIP GOLF COURSE. LOCATED ON #2 GREEN ALONG #3 TEE STATION. BEAUTIFUL VIEW! OPEN CONCEPT KITCHEN BREAKFAST AREA, GREAT <BR><BR><BR>10142503015000..EXCEPTIONAL 4 BDRM., 3.5 BATH, 1991 PARADE HOME IN YORKTOWN SCHOOLS. FIRST FLOOR MASTER BEDROOM INCLUDES LUXURIOUS BATH WITH JACUZZI TUB, GLASS BLOCK SHOWER, WALK-IN CLOSET & <BR><BR><BR>Any help would be greatly appreciated.<BR><BR>Thanks

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## If you had a space or period...

...after the number, it would be easier. But never mind.<BR><BR>How about we chop off all characters that are found before the first *LETTER*? That would also get rid of the two periods in your second example.<BR><BR>&#060;%<BR>txt = ... wherever you are getting those strings from ...<BR><BR>For i = 1 To Len(txt)<BR> letter = UCase(Mid(txt,i,1))<BR> If letter &#062;= "A" AND letter &#060;= "Z" Then<BR> txt = Mid( txt, i ) &#039; get everything from letter onwards<BR> Exit For<BR> End If<BR>Next<BR>%&#062;<BR><BR>If you ever have a string that has no letters at all in it, then it won&#039;t be altered at all. I presume you can live with that.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
635

## Wouldn't a regular expression be better here

A well written expression would solve it nice & quickly non ?<BR><BR>I still can&#039;t write a regular expression without my book so you might have to review this Bill :)<BR><BR>Dim strMyExpression<BR>Dim objRegExp<BR>Dim objMatchCollection<BR><BR>strMyExpression = "/\$([0-9]+)(.+)\$/"<BR>&#039;brackets are to tell RegExp to remember the matches<BR>&#039;[0-9] -&#062; accept only numbers<BR>&#039;.+ -&#062; Accept everything<BR><BR>Set objRegExp = New RegExp<BR>objRegExp.Pattern = strMyExpression<BR>Set objMatchCollection = objRegExp.Match(A String to evaluate)<BR><BR>&#039;If im right, match collection will have two items.<BR>item 1: the random number<BR>item 2: the rest of the string<BR><BR>So just do <BR><BR>MyStringWithoutNumbers = objMatchCollection.item(1).value<BR><BR>Set objRegExp = Nothing<BR><BR>Eniac

4. Member
Join Date
Dec 1969
Posts
66

## RE: If you had a space or period...

Bill,<BR><BR> Thank you very much! That solved my problem!<BR><BR>Thanks,<BR>Ryan

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Okay, but could be even simpler....

Also, you have a bug in that.<BR><BR>\$ means "end of line. You have it fine at end of the expression, but you want ^ at start of it.<BR><BR>Also, when using VBS, you don&#039;t put the /.../ around the pattern.<BR><BR>So:<BR><BR>Set objRegExp = New RegExp<BR>objRegExp.Pattern = "^(d+)"<BR>fixed = objRegExp.Replace( theText, "" )<BR><BR>???<BR><BR>Untested, and I virtually never us VBS regexps, but I think it&#039;s right.<BR><BR>Oh...what the heck...I decided to test it out. Client side VBS, but obviously the code will be same:<BR><BR>**************<BR>&#060;HTML&#062;&#0 60;BODY&#062;<BR>&#060;SCRIPT Language="VBScript"&#062;<BR>Function FixIt( str )<BR> Set re = New RegExp<BR> re.Pattern = "^(d+)"<BR> FixIt = re.Replace( str, "" )<BR>End Function<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;FORM&#062;<BR>&#060;INPU T Name="whatever" Size=50 onChange="me.Value=FixIt(me.value)"&#062;<BR>&#060 ;/FORM&#062;<BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Or if you wanted...

...to get rid of all non-letter characters:<BR><BR>****************<BR>&#060;HTML& #062;&#060;BODY&#062;<BR>&#060;SCRIPT Language="VBScript"&#062;<BR>Function FixIt( str )<BR> Set re = New RegExp<BR> re.Pattern = "^([^a-zA-Z]+)"<BR> FixIt = re.Replace( str, "" )<BR>End Function<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;FORM&#062;<BR>&#060;INPU T Name="whatever" Size=50 onChange="me.Value=FixIt(me.value)"&#062;<BR>&#060 ;/FORM&#062;<BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

#### Posting Permissions

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