How can i cut the string ..???:((

This is a discussion on How can i cut the string ..???:(( within the C++ Programming forums, part of the General Programming Boards category; ei .. i'm new to c++ .. i have a little experience in vb .. my question is how can ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    4

    How can i cut the string ..???:((

    ei .. i'm new to c++ .. i have a little experience in vb .. my question is how can i cut the string in c ++ like in vb ....

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Do you mean tokenize the string? Break it into parts where it's separated by a certain character?

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,673
    Cut the string? You mean make substring from a given string? Use the substr member function.

    Code:
    string str = "Hello World";
    cout << str.substr(6) << endl;   // Outputs "World"
    cout << str.substr(6,2) << endl; // Outputs "Wo"
    cout << str.substr(0,5) << endl; // Outputs "Hello"
    [edit]Please clarify what you mean by "cut".[/edit]
    Last edited by hk_mp5kpdw; 06-09-2005 at 01:44 PM.
    I used to be an adventurer like you... then I took an arrow to the knee.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    yeah !! how can i do that ??

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    I mean break it into parts or cutting it 1 by 1 .. how can i do that ??

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You can refer to individual characters in the array.

    Code:
    char array[30];
    array[0] = 'A'; // first character
    array[1] = 'B'; // second character, etc...

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Do this, write out an example of what exactly you want to do.

    hk_mp5kpdw already gave an example of how to pull substrings out.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    can someone show me a complete running code sample of cutting a string .... i want to cut the string an add it (E.G I input this number 123 , then the output should came out with 6 ) ........ with no limitation in inputing ..

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I doubt anyone's going to write a complete program for you, because this sounds a lot like a homework assignment. You could just run your string through a loop that performed a switch/case statement on each element. If it was a number, add that number to a running total. If it was a null character, exit out of the loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

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