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

Discussion in 'Cadence' started by Suresh Jeevanandam, Aug 4, 2004.

  1. 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.
     
    Suresh Jeevanandam, Aug 4, 2004
    #1
  2. 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 )
    )
    )
    )
     
    Bernd Fischer, Aug 4, 2004
    #2
  3. Suresh Jeevanandam

    S. Badel Guest

    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
     
    S. Badel, Aug 4, 2004
    #3
  4. Thanks bernd, It worked.

    regards,
    Suresh
     
    Suresh Jeevanandam, Aug 4, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.