Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find position 1st occurrence of nonnumeric value in a st
Message
From
10/01/2008 11:13:27
 
 
To
10/01/2008 10:23:45
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01280661
Message ID:
01280887
Views:
16
I did some test and indeed Sergey's solution is in certain conditions two times as fast. (Re: Find position 1st Occurance of nonnumeric value in a str Thread #1280661 Message #1280668) But the performance issue is perhaps not really an issue. My test used a string starting with 10,000 (!) numbers and calculated it a 1000 times. The ISALPHA routine did it all in .8 seconds. Sergey's in .4 seconds.

However, consider a very long string with very many numbers, but nevertheless an alpha character somewhere at the beginning, then the ISALPHA routine definitely wins!

>
>Thanks. I thought of that myself, but this is for a data migration and it could be called hundreds of thousands of times for long strings. I was trying to optimize it somehow. I agree your idea is the safest approach and probably the most accurate.
>
>
>>>lcmyString = "123456789 Boldorn"
>>>
>>>I want to return position 11 because it is the first non numeric position (B). just can't think of it today...
>>
>>Why not write a tiny routine? This one uses ISALPHA().
>>
>>
? FirstPosAlpha( "123456789 Boldorn" )
>>
>>FUNCTION FirstPosAlpha
>>lparameter tcString
>>local ln
>>for ln = 1 to len( m.tcString )
>>	if isalpha( substr( m.tcString, m.ln ) )
>>		RETURN m.ln
>>	endif
>>next
>>RETURN 0
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Previous
Reply
Map
View

Click here to load this message in the networking platform