Finding type of the content of a string : characters or numb

  • Thread starter Suresh Jeevanandam
  • Start date
S

Suresh Jeevanandam

Guest
In skill, I have a string. Am trying to find the content whether a
string of characters or number.

For example,

lstr = list("abc" "1.3")
foreach(str lstr
case( contentType(str)
('charString
println("Its a string of characters.")
v = str
)
('number
println("Its a number")
v = evalstring(str)
)
);case
);foreach

I am looking for a cadence function or some kind of algo that the
contentType() function does here.

Thanks in advance.

regards,
Suresh J.
 
Hi,

I first tried to evaluate the the stings ant then do a kind of
type checking with 'typep' or 'stringp' etc.
But this wont work, I don't get the stings evaluated the way I want.

Then I tried it with regular expressions.
Hope this helps.

lstr = list("abc" "1.3")
foreach( str lstr
cond(
( rexMatchp( "[a-zA-Z]" str )
printf("Its a string of characters: %s.\n" str )
)
( rexMatchp( "[0-9]" str )
printf("Its not a real number, but recognized at: %s.\n" str )
)
)
)

Suresh Jeevanandam wrote:
In skill, I have a string. Am trying to find the content whether a
string of characters or number.

For example,

lstr = list("abc" "1.3")
foreach(str lstr
case( contentType(str)
('charString
println("Its a string of characters.")
v = str
)
('number
println("Its a number")
v = evalstring(str)
)
);case
);foreach

I am looking for a cadence function or some kind of algo that the
contentType() function does here.

Thanks in advance.

regards,
Suresh J.
 
You can use aelNumber which converts a string
to a number. This function recognizes suffixes
like m,u,f etc... as well as scientific notation
with exponent.

if( numberp( aelNumber( str ) ) then
printf( "It's a number" )
else
printf( "It's a string" )
)

this function is not available in pcells, maybe
there are other issues with it so use it carefully.

stéphane


Suresh Jeevanandam wrote:

In skill, I have a string. Am trying to find the content whether a
string of characters or number.

For example,

lstr = list("abc" "1.3")
foreach(str lstr
case( contentType(str)
('charString
println("Its a string of characters.")
v = str
)
('number
println("Its a number")
v = evalstring(str)
)
);case
);foreach

I am looking for a cadence function or some kind of algo that the
contentType() function does here.

Thanks in advance.

regards,
Suresh J.
 
Thanks bernd, It worked.

regards,
Suresh
Bernd Fischer wrote:
Hi,

I first tried to evaluate the the stings ant then do a kind of
type checking with 'typep' or 'stringp' etc.
But this wont work, I don't get the stings evaluated the way I want.

Then I tried it with regular expressions.
Hope this helps.

lstr = list("abc" "1.3")
foreach( str lstr
cond(
( rexMatchp( "[a-zA-Z]" str )
printf("Its a string of characters: %s.\n" str )
)
( rexMatchp( "[0-9]" str )
printf("Its not a real number, but recognized at: %s.\n" str )
)
)
)

Suresh Jeevanandam wrote:

In skill, I have a string. Am trying to find the content whether a
string of characters or number.

For example,
lstr = list("abc" "1.3")
foreach(str lstr
case( contentType(str)
('charString
println("Its a string of characters.")
v = str
)
('number
println("Its a number")
v = evalstring(str)
)
);case
);foreach

I am looking for a cadence function or some kind of algo that the
contentType() function does here.

Thanks in advance.

regards,
Suresh J.
 

Welcome to EDABoard.com

Sponsor

Back
Top