Thread: Stringeling2

  1. #1
    Registered User darketernal's Avatar
    Join Date
    Sep 2001
    Posts
    41

    Stringeling2

    Making a second attempt.


    string = Hello

    'use code to remove 'O' from hello

    string = Hell


    , how can you achieve such without copying the original string.

    'a challenge'

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    What about replacing the last character with a null character?
    Code:
    #include <string.h>
    
    char msg[] = "Hello";
    msg[strlen(msg)-1] = '\0';

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is erase();

    Code:
    std::string sText = "NovemberX";
    sText.erase( // Position
                         9,
                         // Number of elements.
                         1);
    Kuphryn

  4. #4
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378
    string = Hello

    'use code to remove 'O' from hello

    string = Hell


    , how can you achieve such without copying the original string.

    'a challenge'


    one avenue you could go down is create an

    array [4] {"hello"}; //this will set it up as an array of 5 letters but we have set the element to 4. Now just creat an output for it and you should be ready to go.

    cout << name_of_your_output;

    I hope this gets you started in the right direction. Good Luck!!
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  5. #5
    Registered User darketernal's Avatar
    Join Date
    Sep 2001
    Posts
    41
    ( i solved it like this ) *take in context it's C++ Builder*


    Since i had no idea how to (mouse click is the listbox value) i had to figure out how i could assign (as doggiesnot stated) ListBox1->Items->Strings[i] , Getting [i] was very difficult,but it was the right choise.

    My code became the Following

    Added 1 CSpinEdit1.

    Code:
    SpinEdit1->Value = ListBox1->ItemIndex;
    Edit4->Text = ListBox1->Items->Strings[CSpinEdit1->Value];
    This gave a clean string without the garbage.

    So instead of trying to delete the separators and since i invested much time in getting code trying to erase newline's , i ditched that idea did like above, and came to a solution.

    Thank you so much. And also for everyone elses views in this.

Popular pages Recent additions subscribe to a feed