seperating a string

This is a discussion on seperating a string within the C++ Programming forums, part of the General Programming Boards category; I have a string that includes numbers and letters and I want to be able to seperate the string into ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    Question seperating a string

    I have a string that includes numbers and letters and I want to be able to seperate the string into parts. An example of the string looks like this FAP834E. I want to seperate it so that the first letter is seperate (F), the second and third are together (AP), the fourth and fifth are together (83), the sixth is seperate (4) and the last is seperate (E).

    Please letme know if you can help me

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Is it always that same sequence?

    1
    23
    45
    6
    7
    Woop?

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    Create variables for each section of the string you want saved, then iterate through string an copy the corresponding values to the variables.

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Are you using std::string or a char array (pointer)?

    For a std::string you can use substr
    Code:
    std::string myStr = "FAP834E";
    int start = 0;
    std::string first = myStr.subStr(start, 1); //F
    start += 1;
    std::string second = myStr.subStr(start, 2); //AP
    start += 2;
    ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21