AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Remove double spaces

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
delta



Joined: 16 Feb 2005
Posts: 44

PostPosted: Fri Aug 26, 2005 9:52 pm    Post subject: Remove double spaces Reply with quote

I have a string in which I want to contract double spaces to single spaces.

I was trying this:
Code:
StringReplace, word, word, %A_Space%%A_Space%, %A_Space%, All

No success. So I tried
Code:
AutoTrim, Off
StringReplace, word, word, %A_Space%%A_Space%, %A_Space%, All

Still the same.
I tried
Code:
AutoTrim, Off
ds := "  "
s := " "
StringReplace, word, word, %ds%, %s%, All

and still no success. Sad

Then I tried
Code:
StringReplace, word, word, aa, a, All

and it worked right away. So what's wrong with those spaces? How do I have to do it?
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Sat Aug 27, 2005 1:13 am    Post subject: Reply with quote

Most of those examples should work okay. For example, I tested the following and it produces the right answer:
Code:
word = 12  34  56
StringReplace, word, word, %A_Space%%A_Space%, %A_Space%, All

However, the above will not work completely if you have any triple-spaces, quad-spaces, etc. In that case, you could try the following:
Code:
Loop
{
    StringReplace, word, word, %A_Space%%A_Space%, %A_Space%, UseErrorLevel
    if ErrorLevel = 0  ; No more replacements needed.
        break
}
Back to top
View user's profile Send private message Send e-mail
delta



Joined: 16 Feb 2005
Posts: 44

PostPosted: Sat Aug 27, 2005 5:25 am    Post subject: Reply with quote

Actually, that's about the same lines I had to replace multiple spaces. Wink Seeing you using those as well I concluded that the error must be elsewhere. A hex viewer finally revealed that there were no multiple spaces but multiple tabs! But they sure looked like spaces! Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group