CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    split a string over two lines

    How I can split the following string in two or more lines?

    Code:
    string test = "its something unpredictable but in the end is right. I hope you had the time of your life.";
    which set of buttons should I use to split it like this and the string will be still logicaly one line

    Code:
    string test = "its something unpredictable 
                          but in the end is right. 
                          I hope you had the time of your life.";
    this is helpful to send queries to the DB's

  2. #2
    Join Date
    May 2004
    Location
    Osijek
    Posts
    61

    Re: split a string over two lines

    Something like this:
    Code:
    string test = @"its something unpredictable 
                          but in the end is right. 
                          I hope you had the time of your life.";

  3. #3
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Re: split a string over two lines

    but for example I target the point which I want into the new line, afterwards if I simply press ENTER the string at the next line wont be red anymore and it wont belong anymore to the previous line.

    Is there any set of buttons like ctrl + ? to make this new line without loss this property?

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: split a string over two lines

    Try this :

    Code:
    string test = "its something unpredictable" + Environment.NewLine +
                         "but in the end is right." + Environment.NewLine +
                         "I hope you had the time of your life.";
    And for the puritans out there :

    Code:
    StringBuilder testStringBuilder = new StringBuilder();
    testStringBuilder.AppendLine("its something unpredictable");
    testStringBuilder.AppendLine("but in the end is right.");
    testStringBuilder.AppendLine("I hope you had the time of your life");
    string test = testStringBuilder.ToString();
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  5. #5
    Join Date
    May 2004
    Location
    Osijek
    Posts
    61

    Re: split a string over two lines

    Quote Originally Posted by raulbolanos View Post
    but for example I target the point which I want into the new line, afterwards if I simply press ENTER the string at the next line wont be red anymore and it wont belong anymore to the previous line.

    Is there any set of buttons like ctrl + ? to make this new line without loss this property?
    I am not exactly sure what question is, but if you are thinking about some command that will automatically generate multiple lines from one, that is not available.

    If you want multiple lines in one variable, you must press enter where you want line break.

    However, you could make some macro for that...

  6. #6
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Re: split a string over two lines

    Quote Originally Posted by jmedved View Post
    I am not exactly sure what question is, but if you are thinking about some command that will automatically generate multiple lines from one, that is not available.

    If you want multiple lines in one variable, you must press enter where you want line break.

    However, you could make some macro for that...
    Oh, I see... thank you.

  7. #7
    Join Date
    Mar 2009
    Location
    Stuttgart, Germany
    Posts
    56

    Re: split a string over two lines

    Quote Originally Posted by jmedved View Post
    Something like this:
    Code:
    string test = @"its something unpredictable 
                          but in the end is right. 
                          I hope you had the time of your life.";
    You were right... I only need the '@' character.

    Thank you very much.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured