Jump to content

How to replace leading and trailing spaces from a string


Recommended Posts

No Trim function?

the script below is converting large html files to prepare for using in an autoit functions.

for example a line in like "space space space space<link rel="stylesheet" href="docs/style.css" type="text/css"> space space space space"

with lots leading and trailing spaces.....how to clean them out best way please?

#include<Array.au3>
#include<File.au3>
Dim $a_Test,$b_result
; Read file into array
_FileReadToArray("C:\Program Files\AutoIt3\beta\Will\openwysiwygv1.4.6cWill\exampleWill.html",$a_Test)
For $line = 1 to UBound($a_Test)-1
    If StringLen($a_Test[$line]) > 0 Then
    $a_Test[$line]= StringRegExpReplace($a_Test[$line], "  ", "")
    ;If StringInStr($a_Test[$line], "  ") Then $a_Test[$line]=StringReplace($a_Test[$line], "  ","")    
    If StringInStr($a_Test[$line], """") Then $a_Test[$line]=StringReplace($a_Test[$line], """","""""")

        $a_Test[$line]="$temp &= """ & $a_Test[$line] & """ & @CRLF"
        ;MsgBox(0,"",$a_Test[$line])
    EndIf
Next
;;_ArrayReverse($a_Test,1)
; write reversed array to file
_FileWriteFromArray("test2.txt",$a_Test,1)
Edited by Will66
Link to comment
Share on other sites

All the string functions start with "String" so you could scan the index in the help file. Or, under Search, putting in "spaces" returns StringStripWS as the first result.

certainly does, I was searching like "replace" and "trim"......not listed in either of those searches.....

I expected it to be related.

Edited by Will66
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...