Thread: Break up text at newline

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    27

    [SOLVED] Break up text at newline

    I'm trying to take text from a multiline text input and break it up to into
    string Address[7] but to do this I need to know how to break the text up at \n

    so if I have "Hello world\nI am mikey\nThis is line 3"
    I need to break it up to fill the different indexes

    So far I have this but need to join beginning and end.

    Code:
    void _labelguiFrame::OnButton2Click(wxCommandEvent& event)
    {
        //Get address from box
        wxString instring = AddressTextIn->GetValue();
        //Process address to insert spacings at beginning of lines
        //Break up string to lines
        string address[7];
        //!!!More code here...!!!
    
        //Reform with added spaces
        //str length for labels is 26, so 3+22+3
        string linebegin = "   ";
        string printstring;
        int x = 0;
        int y = 7;
        while (x<y) {
            //Address output here
            if ( x < y - 1 ) {
                printstring = printstring + linebegin + address[x] + "\n";
            }
            else {
                printstring = printstring + linebegin + address[x];
            }
            cout<<linebegin<<address[x]<<endl;
            x++;
        };
        //Address to the printer
        //Setup printer
        ofstream print;
        print.open("lpt1:", ios::out);
        //cout<<printstring;
        print<<"\x1b\x43\x09";
        print<<printstring;
        print<<"\x1b\x0c\x1b\x07\x1b\x07";
        print.close();
        wxMessageBox(_("The label has printed.\nPlease peel it off and press\nreturn when label has been ejected."));
        //End print job by resetting printer, and pulling back paper.
        print.open("lpt1:", ios::out);
        print<<"\x1b\x40";
        print.close();
    }
    Last edited by mikeyp; 12-13-2009 at 02:28 PM. Reason: Debugged code + solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. Keypress reading
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 12:16 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM