EmptySpace Posted April 25, 2013 Share Posted April 25, 2013 Hey, I need some help from you guys. For example my text text just text wait wut after script work: text,just,text,wait,wut Maybe I need to use StringRegExp()? I never used it before. So ok my code: #include Global $pw = FileOpen("textwithspaces.txt") Global $hOutPutFile = FileOpen("nospaces.txt", $FO_OVERWRITE) $hash = FileRead($pw) ;I need array loop or something? ;I would try to read line by line and use stringinstr or smth but I beleive there is faster way WEnd FileClose($pw) FileClose($hOutPutFile) Link to comment Share on other sites More sharing options...
jdelaney Posted April 25, 2013 Share Posted April 25, 2013 (edited) stringRegExpReplace ($hash,chr(32),",")or just stringreplace Edited April 25, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
MyEarth Posted April 25, 2013 Share Posted April 25, 2013 (edited) Easy task #include <File.au3> $sData = "text just text wait wut" $FileName = "Test.txt" $hFile = FileOpen($FileName, 2) FileWrite($hFile, $sData) FileClose($hFile) $hFileOpen = FileOpen($FileName) $ReadData = FileRead($hFileOpen) FileClose($hFileOpen) $sNewFile = StringReplace($ReadData, chr(32), ',') $hFileOpen = FileOpen($FileName, 2) FileWrite($hFileOpen, $sNewFile) FileClose($hFileOpen) ShellExecute('test.txt') Edited April 25, 2013 by MyEarth Link to comment Share on other sites More sharing options...
EmptySpace Posted April 25, 2013 Author Share Posted April 25, 2013 Thanks! Link to comment Share on other sites More sharing options...
kylomas Posted April 25, 2013 Share Posted April 25, 2013 EdgarT, In case there are multiple spaces between the tokens, a comma already present or you want to span multiple lines. #include <Constants.au3> #AutoIt3Wrapper_Add_Constants=n ;=================================================================================== ; create test file ;=================================================================================== $str = 'token1 token2 token3 token4 token5' & @crlf & _ 'token6, token7,token8' & @crlf & _ 'token9' & @crlf & _ 'token10,token11 token12' local $hfl = fileopen (@scriptdir & '\test.txt',2) filewrite ($hfl,$str) fileclose($hfl) ;=================================================================================== ; read file and replace all spaces between words with a ',', if one does not exist ;=================================================================================== msgbox($mb_ok,'Text Before',fileread(@scriptdir & '\test.txt')) msgbox($mb_ok,'Text After ',stringregexpreplace(fileread(@scriptdir & '\test.txt'),'\b(\x20)+\b',',')) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted April 25, 2013 Share Posted April 25, 2013 (edited) good call...or: $string = stringRegExpReplace ("text just text wait wut", chr(32)&"+",",") although, yours would be good if you don't want to replace leading/trailing spaces Edited April 25, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
mikell Posted April 25, 2013 Share Posted April 25, 2013 And to avoid double commas $string = stringRegExpReplace ("text, just text, wait wut", '[\h,]+', ",") msgbox(0,"", $string) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now