5 Replies Latest reply: Nov 13, 2017 11:25 AM by Camillo Rospigliosi RSS

    Remove newline in string



      I would like to replace all newline characters by spaces in a string.


      I have tried :

      string.replace(input.my_string,'\r',' ')


      string.replace(input.my_string,'\n',' ')


      But it doesn't seem to work.


      Am I missing something?




        • Re: Remove newline in string
          Sree Nivas

          Add sample data

            • Re: Remove newline in string

              I get the data from a SQL Server database.


              I have a carriage return / new line in the data, and a way to eliminate them is to do it in the SQL query :




              I was looking for a way to do it in datascript.



            • Re: Remove newline in string

              You have the correct approach, but you used the wrong pattern.  The return/new line combination should be specified as control characters not as their string representations.  Also, the actual entry may be a combination of return and new line, not just one of these control characters.  The correct function call would be

              string.replace(input.my_string, "%c+", "").


              The pattern "%c+" specifies 1 or more control characters.


              There is an easy way to test your coding.


              • Open an Expressor command window.
              • Enter the command datascript to start the interactive command line interpreter.
              • Use the square braces to demarcate your string; this allows you to define a string value that includes new lines.  That is:
                my_string =
              • Then try out your code.
                my_string2 = string.replace(my_string,"%c+"," ")
              • And print out the result
              • Re: Remove newline in string



                I have similar problem.

                I would like to insert already in script some function that removes "enters".

                Unfortunately something described here  - string.replace(input.my_string, "%c+", "") - doesn't work.

                Could anybody help me?