Re: how to tell it is character or it is number? [message #55209] |
Tue, 07 August 2007 10:59 |
queiny
Messages: 15 Registered: November 2005
|
Junior Member |
|
|
Many thanks!!
I think both of your suggestions work for me. Someone also suggest use
function 'byte' to see whether it is number or character.
>> http://idlastro.gsfc.nasa.gov/ftp/pro/misc/valid_num.pro
>
> I would just try stregex. From what you've shown so far, all it would
> take is this:
>
> if stregex( string, '[^0-9]', /boolean ) then ; this not numeric
> else ; this is numeric
>
> that is assuming, of course, that the numeric data you will be
> checking only contains the numbers 0-9. If you have negative signs,
> or decimal points, or whitespace, then above regular expression will
> have to be adjusted accordingly.
|
|
|
Re: how to tell it is character or it is number? [message #55211 is a reply to message #55209] |
Tue, 07 August 2007 10:48  |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
just use the byte function and check the values. Numbers 0-9 have ASCII
values of 48-57 dec or 30-39 hex. Haje
"queiny" <queiny98@yahoo.com> wrote in message
news:1186499635.496862.33320@d55g2000hsg.googlegroups.com...
> Hi,
>
> I am reading in many line of mixed characters and numbers.
>
> AA,01,02,003,andefg
> BB,02,03,006,edjkflg
> ......
> FF,01,02,abc,eirjfdkf
> ......
>
> I need information from the 4th field, which can be either number or
> character. After I parsed the long records, I singled out this field.
> Is there a way I can tell whether it is numbers or it is characters?
> 'fix' command can convert the numbers, it will give an error message
> then continue to the execution.
>
> Thanks,
>
|
|
|
Re: how to tell it is character or it is number? [message #55213 is a reply to message #55211] |
Tue, 07 August 2007 10:41  |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Aug 7, 11:38 am, wlandsman <wlands...@gmail.com> wrote:
>> Is there a way I can tell whether it is numbers or it is characters?
>> 'fix' command can convert the numbers, it will give an error message
>> then continue to the execution.
>
> There are lots of programs around to do this, with two variants. The
> first tests, as you suggest, whether IDL can convert the string into a
> numeric value
>
> http://idlastro.gsfc.nasa.gov/ftp/pro/misc/strnumber.pro
>
> But IDL will consider the string '1qz_3' to be a valid number (=1) so
> if you want a more usual interpretation, you need a more detailed
> test of whether the ordering of digits, letters and decimal points
> make sense as in
>
> http://idlastro.gsfc.nasa.gov/ftp/pro/misc/valid_num.pro
>
> --Wayne
I would just try stregex. From what you've shown so far, all it would
take is this:
if stregex( string, '[^0-9]', /boolean ) then ; this not numeric
else ; this is numeric
that is assuming, of course, that the numeric data you will be
checking only contains the numbers 0-9. If you have negative signs,
or decimal points, or whitespace, then above regular expression will
have to be adjusted accordingly.
|
|
|
|