Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, How would I go about defining a variable from a document name. Example: document01.doc I want to take the 01 and set X to equal integer 1. Thanks ...
  1. #1
    Linux Guru jmadero's Avatar
    Join Date
    Jul 2007
    Location
    California
    Posts
    1,958

    C++ Get Variable Name from Document Name

    Hi All,

    How would I go about defining a variable from a document name. Example:

    document01.doc

    I want to take the 01 and set X to equal integer 1. Thanks all
    Bodhi 1.3 & Bodhi 1.4 using E17
    Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17

    "The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    As you already know the extension, you begin by stripping ".doc" from the string.
    Then you look, one character at a time, from the right side at each character.
    You check each character whether it is a digit (isdigit) and stop if it is not.

    This way you know there are two consecutive digits in this string. You strip the rest and transform the string to a integer number with atoi.
    Debian GNU/Linux -- You know you want it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...