Loading ...
Sorry, an error occurred while loading the content.

How do you replace a New Line control character in a string?

Expand Messages
  • lafmi01@ca.com
    How do you replace a New Line control character in a string? I know the doc reads that Tab and line-break tokens are automatically converted to their real
    Message 1 of 5 , Apr 6, 2001
    • 0 Attachment
      How do you replace a New Line control character in a string? I know
      the doc reads that "Tab and line-break tokens are automatically
      converted to their real characters since version 4.6", but I don't
      haven't got a clue as how to check for it.

      Here is what I've tried so far... (without the silly word wrap of
      course)

      ^!Setdebug on
      ^!Set %String%=12345^%NL%

      ^!Set %RmvToken%=^$StrReplace(^%NL%;^%Empty%;^$UseTokens(^%String%)
      $;True;True)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace(^%NL%;^%Empty%;^$UseTokens(^%String%)
      $;True;False)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace(^%NL%;^%Empty%;^$UseTokens(^%String%)
      $;False;True)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace(^%NL%;^%Empty%;^$UseTokens(^%String%)
      $;False;False)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace("^P";^%Empty%;^$UseTokens(^%String%)
      $;True;True)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace("^P";^%Empty%;^$UseTokens(^%String%)
      $;True;False)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace("^P";^%Empty%;^$UseTokens(^%String%)
      $;False;True)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %RmvToken%=^$StrReplace("^P";^%Empty%;^$UseTokens(^%String%)
      $;False;False)$
      ^!Info String=^$UseTokens(^%String%)$ RmvToken=^$UseTokens(^%
      RmvToken%)$

      ^!Set %Right%=^$StrCopyRight(^$UseTokens(^%String%)$;1)$
      ^!Info Right=^%Right%

      Mike LaFountain lafmi01@...
    • Alan C.
      Hi Mike, ... H= Replace cr/lf ^!Replace ^p ~~|##|~~ AWS The above little clip will replace all in a document. But U just wanted a string.
      Message 2 of 5 , Apr 7, 2001
      • 0 Attachment
        Hi Mike,

        At 04:15 PM 4/6/01 +0000, you wrote:
        >How do you replace a New Line control character in a string? I know
        >the doc reads that "Tab and line-break tokens are automatically
        >converted to their real characters since version 4.6", but I don't
        >haven't got a clue as how to check for it.
        <snip>


        H="Replace cr/lf"
        ^!Replace "^p" >> "~~|##|~~" AWS


        The above little clip will replace all in a document. But U just wanted a string. Perhaps substitute H option in place of the AW above then the clip would work only on a selected area in a doc.

        my test doc was a new doc in Ntab that I typed in 4 or five short lines of text then ran the clip. worked good.

        HTH. Alan.
      • RS
        Hi Mike, Alan, ... You forgot my old time favorite: ^$StrReplace$. For example, if you have your text in the s variable and want to replace NLs with a vertical
        Message 3 of 5 , Apr 7, 2001
        • 0 Attachment
          Hi Mike, Alan,

          At 09:07 PM 04/07/01 -0700, you wrote:
          >Hi Mike,
          >
          >At 04:15 PM 4/6/01 +0000, you wrote:
          >>How do you replace a New Line control character in a string? I know
          >>the doc reads that "Tab and line-break tokens are automatically
          >>converted to their real characters since version 4.6", but I don't
          >>haven't got a clue as how to check for it.
          ><snip>
          >
          >
          >H="Replace cr/lf"
          >^!Replace "^p" >> "~~|##|~~" AWS
          >
          >


          You forgot my old time favorite: ^$StrReplace$.

          For example, if you have your text in the s variable and want to replace
          NLs with a vertical bar for a wizard's list, use:

          ^!Set %s%=^$StrReplace("^%NL%";"|";"^%s%";True;False)$

          It is always preferable to use ^%NL%. In some cases the "^p" token doesn't
          act as expected.

          (I just noticed the example in ClipWriter uses the old "^p", no need to
          tell me. Will be fixed in the next update.)


          Best regards,

          Ramon Silvera

          ----------------------------------------------------------------------------
          ------------------
          ClipWriter 2.5 is now available:

          Find the commands you need quickly. Understand clips written by others.
          And whether you are an advanced programmer or just a beginner,
          write clips faster, easier, more efficiently ...!

          http://ptools.home.att.net/ClipWriter/cw.htm

          ----------------------------------------------------------------------------
          ------------------
        • lafmi01@ca.com
          Thanks Ramon, I finally did get this to work with the following statment from the actual clip: ^!Set %RmvToken%=^$StrReplace( ^^p ;^%Space%;^$UseTokens(^%
          Message 4 of 5 , Apr 8, 2001
          • 0 Attachment
            Thanks Ramon,

            I finally did get this to work with the following statment from the
            actual clip:

            ^!Set %RmvToken%=^$StrReplace("^^p";^%Space%;^$UseTokens(^%
            P_BlockArray^%x%%)$;False;True)$

            I had tried to use ^%NL% as in the original message but it didn't
            work. I think the difference is that you used "^%NL%" as I did
            with "^^p". I don't understand why the quotes are needed for the
            syntax of this command to work... can some greater mind than mine on
            this list please explain?


            > For example, if you have your text in the s variable and want to
            replace
            > NLs with a vertical bar for a wizard's list, use:
            >
            > ^!Set %s%=^$StrReplace("^%NL%";"|";"^%s%";True;False)$
            >
            > It is always preferable to use ^%NL%. In some cases the "^p" token
            doesn't
            > act as expected.
            >
            > (I just noticed the example in ClipWriter uses the old "^p", no
            need to
            > tell me. Will be fixed in the next update.)
            >
            >
            > Best regards,
            >
            > Ramon Silvera
            >
          • RS
            Hello Mike, ... Anytime. ... String variables should always be quoted, when used in functions, to make sure they are interpreted as expected by NoteTab.
            Message 5 of 5 , Apr 8, 2001
            • 0 Attachment
              Hello Mike,

              At 04:04 PM 04/08/01 -0000, you wrote:
              >Thanks Ramon,

              Anytime.


              >I finally did get this to work with the following statment from the
              >actual clip:
              >
              >^!Set %RmvToken%=^$StrReplace("^^p";^%Space%;^$UseTokens(^%
              >P_BlockArray^%x%%)$;False;True)$
              >
              >I had tried to use ^%NL% as in the original message but it didn't
              >work. I think the difference is that you used "^%NL%" as I did
              >with "^^p". I don't understand why the quotes are needed for the
              >syntax of this command to work... can some greater mind than mine on
              >this list please explain?
              >

              String variables should always be quoted, when used in functions, to make
              sure they are interpreted as expected by NoteTab. Occasionally, you might
              find one or another case where it will work without quotes. But it is best
              to play it safe and always use quotes.

              The only place a string variable must *not* be quoted is in the second
              parameter of certain commands like, for example:

              ^!TextToFile "^%MyFile%" ^%MyText%

              In this type of command, the first variable should be quoted, but the
              second not. (Otherwise, the text in the file will be quoted.)


              Regards,

              Ramon Silvera
            Your message has been successfully submitted and would be delivered to recipients shortly.