String Commands

AutoIt

Q #1: How do I remove spaces from a string?
      I am removing spaces from telephone numbers as I am using ini files as
      data storage for connection (plus other) information about remote
      sites. While my current modem will pause for 5 secs on a space my ISDN
      TA "see's" a space as a delimeter i.e. the number 01234 567890 would
      be to dial 01234 using security protocol 567890 (which is invalid)

      I have attempted to use the

      StringReplace, Number, No,  ,
            and
      StringReplace, Number, No, " ",

      function, but it won't find spaces. I have attempted nibbling the Variable
      (1 char at a time)

      ; ======= Scriptlet Starts Here =======
      Start:
      StringLeft, TST, No, 1
      StringTrimLeft, No2, No, 1
      SetEnv, No, %No2%
      IfNotEqual, TST, , SetEnv, %Number%%TST%
      Goto, Start
      ; ======= Scriptlet Ends Here =======

      but I lose the whole thing then and I don't know why It should add the
      chars 1 by one to the Number variable unless it is a space.

      ---------------------------------------------------------------------

A #1: Use the space trimming to your advantage!  This works if you just want to
      remove spaces.  If you want to replace them with something else it doesn't
      work.

      ; ======= Scriptlet Starts Here =======
      ; For a general removal of spaces:

      SetEnv, test, this is a test   A really   go od te s t
      SetEnv,Output,
      loop:
      StringLeft,dummy,test,1
      SetEnv,Output,%output%%dummy%
      StringTrimLeft,test,test,1
      IfNotEqual,test,,goto,loop
      MsgBox,0,test,%output%
      ; ======= Scriptlet Ends Here =======

      ---------------------------------------------------------------------

A #2: Dump the data to a ini file and strip all the spaces with an external
      program such as GSAR (general search and replace (DOS)).

      ; ======= Scriptlet Starts Here =======
      FileReadLine, No, numbers.txt, %Ln%
      IniWrite, %No%, temp.ini, Temp, Number
      RunWait, %COMSPEC% /C gsar -io "-s " -r %S%temp.ini, c:\\temp, Min
      IniRead, Number, temp.ini, Temp, Number
      ; ======= Scriptlet Ends Here =======

      ---------------------------------------------------------------------

A #3: You can do a script with KiXtart 95...  All you need is a way to make the
      two scripts comunicate with an ini file.

      First of all, you need to find the place of each space, then you begin to
      remove them from end to start...

      you'll do something like:

      ; ======= Kixtart Scriptlet Starts Here =======
      $InputStringLen = Len($InputString)
      $FirstStringChar = $SpaceChar - 1
      $SecondStringChar = $SpaceChar + 1
      $FirstString = SubStr($InputString, 0,
      $FirstStringChar)
      $SecondString = SubStr($InputString,
      $SecondStringChar, $InputStringLen)
      $CoolString = $FirstString + $SecondString
      ; ======= Kixtart Scriptlet Ends Here =======

      This way you can remove the spa

-----------------------------------------------------------------------------

Q #2: This is the first time I use a string command. I have made this:
 
      ; ======= Scriptlet Starts Here =======
      WinGetActiveTitle, CLIPBOARD
      StringLeft, CLIPBOARD, PROGNAME, 10
      IfNotEqual, PROGNAME, EPLAN 5.30, Goto, exit
      ; ======= Scriptlet Ends Here =======
 
      I get an error on the line with stringleft. What am I doing wrong?

      ---------------------------------------------------------------------

A #1: Change the line to

      StringLeft, PROGNAME, CLIPBOARD, 10

      The syntax is:

      StringLeft, <Output Var>, <Input Var>, <number of chars to extract>

-----------------------------------------------------------------------------

Q #3: Is there a way to return the position of a substring within a string?
      I want to delete all text from the beginning of a line up to a colon.

      ---------------------------------------------------------------------

A #1: Use "StringGetPos".

      ---------------------------------------------------------------------

A #2: If you don't have version 2.6 or above, then try something like

      ; ======= Scriptlet Starts Here =======
      Setenv, test, This is a string: Test String
      stringlen, strlen, test
      setenv, count,1
      loop:
        stringmid, strtest, test, %count%, 1
        ifequal, strtest, :, goto, foundit
        envadd, count, 1
        ifgreater, count, %strlen%, goto, notfound
        goto, loop
      foundit:
        stringmid, output, test, %count%, %strlen%
        msgbox, 0, Result, The resulting string is %output%
        goto, end
      notfound:
        msgbox, 0, Error, No colon found
      end:
      ; ======= Scriptlet Ends Here =======

      note, if you don't want the colon, add one to the
      count before getting the output string

-----------------------------------------------------------------------------

Q #4: Is there a detected difference between reading a line with a blank
      space and carriage return vs. just a carriage return?

      ---------------------------------------------------------------------

A:    Yes.  For an example try:

      ; ======= Scriptlet Starts Here =======
      Filereadline,test1,c:\\testspace.txt,1
      Setenv,test2,--%test1%--
      IfEqual,test2,-- --,Msgbox,0,Test,There is a space!
      IfEqual,test2,----,Msgbox,0,Test,There is no space!
      ; ======= Scriptlet Ends Here =======