Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to Add Carriage return line feed to string (globalization)

How to Add Carriage return line feed to string (globalization)

Scheduled Pinned Locked Moved Visual Basic
helpquestiontutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Georg Kohler
    wrote on last edited by
    #1

    Here is todays little problem :-) Usually I would write soemthing like this : ErrorMessage = "First Line" & vbCrLf & "second Line" MSGbox(ErroMessage) - This will produce a two line message What I need to do is to write the code like this ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original. MSGbox(ErroMessage) should then also display two lines How do I do this the most straigh forward way ? The reason I'm trying to do this is for globalization of our software This approach would make it easy to translate any error message into another language thanks Georg

    W L 2 Replies Last reply
    0
    • G Georg Kohler

      Here is todays little problem :-) Usually I would write soemthing like this : ErrorMessage = "First Line" & vbCrLf & "second Line" MSGbox(ErroMessage) - This will produce a two line message What I need to do is to write the code like this ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original. MSGbox(ErroMessage) should then also display two lines How do I do this the most straigh forward way ? The reason I'm trying to do this is for globalization of our software This approach would make it easy to translate any error message into another language thanks Georg

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Georg Kohler wrote:

      ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original.

      But you constuct it programmatically or is this string stored somewhere else? The problem is that I don't see the difference between those two variations is you still create the message text in the program.

      The need to optimize rises from a bad design.My articles[^]

      G 1 Reply Last reply
      0
      • G Georg Kohler

        Here is todays little problem :-) Usually I would write soemthing like this : ErrorMessage = "First Line" & vbCrLf & "second Line" MSGbox(ErroMessage) - This will produce a two line message What I need to do is to write the code like this ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original. MSGbox(ErroMessage) should then also display two lines How do I do this the most straigh forward way ? The reason I'm trying to do this is for globalization of our software This approach would make it easy to translate any error message into another language thanks Georg

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, if you want the multi-line string to be a single string in your database or your localized resource, how about this: - use a special substring to indicate NEWLINE (e.g. use \n like C/C++/Java/C# do) - then replace it by actual newline at run-time; in VB.NET that would be myString=myString.Replace("\n", Environment.NewLine) I don't know how it would look in ancient VB. - obviously reading the database/resource and replacing \n would fit nicely in a little method/function. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).


        modified on Sunday, January 18, 2009 5:33 PM

        G 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, if you want the multi-line string to be a single string in your database or your localized resource, how about this: - use a special substring to indicate NEWLINE (e.g. use \n like C/C++/Java/C# do) - then replace it by actual newline at run-time; in VB.NET that would be myString=myString.Replace("\n", Environment.NewLine) I don't know how it would look in ancient VB. - obviously reading the database/resource and replacing \n would fit nicely in a little method/function. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).


          modified on Sunday, January 18, 2009 5:33 PM

          G Offline
          G Offline
          Georg Kohler
          wrote on last edited by
          #4

          Actually that's what I ended up doing last night .. I was just "fishing" to see if there is a different way to do this I ended up using @LF@ as the string to be replaced by the Environment.NewLine I have to look int using \n instead - stick to the standard if possible ... Anyway - thanks for taking the time to answer my question :-) As always "you guys" haven been great! Georg

          L 1 Reply Last reply
          0
          • G Georg Kohler

            Actually that's what I ended up doing last night .. I was just "fishing" to see if there is a different way to do this I ended up using @LF@ as the string to be replaced by the Environment.NewLine I have to look int using \n instead - stick to the standard if possible ... Anyway - thanks for taking the time to answer my question :-) As always "you guys" haven been great! Georg

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            You're welcome. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).


            1 Reply Last reply
            0
            • W Wendelius

              Georg Kohler wrote:

              ErrorMessage = "First Line ??Linefeed?? second Line" - Notice This is just one continius string not an assembled string as in the original.

              But you constuct it programmatically or is this string stored somewhere else? The problem is that I don't see the difference between those two variations is you still create the message text in the program.

              The need to optimize rises from a bad design.My articles[^]

              G Offline
              G Offline
              Georg Kohler
              wrote on last edited by
              #6

              Actually there is a difference - at least it seems to me :rolleyes:

              ErrorMessage = "First Line" & vbCrLf & "second Line"
              ' This will produce a two line message
              ErrorMessage = "First Line vbCrLf second Line"
              ' will not produce a two line message

              (maybe replacing VBCrlf with something else would also work - but here is my solution so far)

              LogMessage = "First Line \n second Line"
              LogMessage = LogMessage.Replace("\n", Environment.NewLine)
              MSGbox(Logmessage) ' will again produce a two line message

              "First Line \n second Line" is what get's stored as a resource - as you can see it will be easy to change this into another language as you can add the line feeds wherever you need to. In my code I also add Variables to the message - again this will allow for easy translation into another language. A typical error message might look like this

              " Error detected in line \VAR1 \n Dublicate \Var2 values detected!"

              This might end up looking like this: ..... Error detected in line 12 Dublicate N values detected! ....

              W 1 Reply Last reply
              0
              • G Georg Kohler

                Actually there is a difference - at least it seems to me :rolleyes:

                ErrorMessage = "First Line" & vbCrLf & "second Line"
                ' This will produce a two line message
                ErrorMessage = "First Line vbCrLf second Line"
                ' will not produce a two line message

                (maybe replacing VBCrlf with something else would also work - but here is my solution so far)

                LogMessage = "First Line \n second Line"
                LogMessage = LogMessage.Replace("\n", Environment.NewLine)
                MSGbox(Logmessage) ' will again produce a two line message

                "First Line \n second Line" is what get's stored as a resource - as you can see it will be easy to change this into another language as you can add the line feeds wherever you need to. In my code I also add Variables to the message - again this will allow for easy translation into another language. A typical error message might look like this

                " Error detected in line \VAR1 \n Dublicate \Var2 values detected!"

                This might end up looking like this: ..... Error detected in line 12 Dublicate N values detected! ....

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                I think that's a very good solution. I've used that system a lot. The only thing is that you may consider running the replace twice. First put the variables in place and then format the string with newlines. I sometimes have strings in variables that also contain \n. Doing this in two phases also replaces the newlines from variables correctly.

                The need to optimize rises from a bad design.My articles[^]

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups