Finding a number in Text
Posted: Mon Jul 25, 2005 5:12 pm
				
				Hello PB users,
I'm trying to find a number in a line a text. I tried this but PB doesn't return 0 when you Valf("Text") like some BASICS do.
Any ideas? I want it to pick out the 3 in this sentence: "min 3 inches wood around." Something like that.
Here are the procedures for use in the code above:
			I'm trying to find a number in a line a text. I tried this but PB doesn't return 0 when you Valf("Text") like some BASICS do.
Code: Select all
Procedure.f GetNumber(Text$)
For index = 1 To WordCount(Text$)
   If ValF(StringField(Text$,index," ")) * 1.0
      ProcedureReturn = StrF(StringField(Text$,index," "))
   EndIf
Next index
EndProcedure
Here are the procedures for use in the code above:
Code: Select all
Procedure.s RemoveExtraSpaces(Text$)
  While FindString(Text$,"  ",1) : Text$ = ReplaceString(Text$,"  "," ", 1) : Wend
ProcedureReturn Text$
EndProcedure
Procedure.l WordCount(Text$)
count.l = 1 : Text$ = RemoveExtraSpaces(Text$)
 While StringField(Text$, count, " ") : count + 1 : Wend
ProcedureReturn count - 1
EndProcedure