# 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
_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

##### Share on other sites

I think what you're looking for is StringStripWS () Check it out in the helpfile

##### Share on other sites

thanx, did the trick........ its annoying that stuff like that doesn't come up under the Related links of (for eg) StringReplace function in the help file.

##### 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.

##### 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

## Create an account

Register a new account