Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • June 23, 2017, 12:30:26 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: T h i s i s a v e r y s h o r t s c r i p t - This is a very short script  (Read 1381 times)

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
Delete one space between letters in distorted text lines .

The target is select the text we want to transform and apply the measure.


Best Regards


AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,138
    • View Profile
    • Donate to Member
As I told you already, nobody can know which space to delete and which not.





 

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 7,934
    • View Profile
    • Donate to Member
Couldn't this be done with "Find and Replace"?

  • Select the text you want to modify.
  • Do a search for " "
  • Do a replace for ""
  • Done.
« Last Edit: March 10, 2017, 09:39:43 PM by Deozaan »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,765
    • View Profile
    • Donate to Member
As I told you already, nobody can know which space to delete and which not.

Actually, so long as distorted text has extra spaces between ALL characters (which includes the space character), you can make this work.  Every real space will have two spaces instead of one so you can do it like this:

Code: Autohotkey [Select]
  1. #T:: ; Windows+T hotkey.  Change as desired.
  2. {
  3.     ; T h i s  i s  a  v e r y  s h o r t  s c r i p t  ; Sample of distorted text.
  4.     ;        ^^   ^^ ^^       ^^         ^^             ; Double spaces where single spaces should be.
  5.  
  6.     Clipboard := "" ; Empty the clipboard.
  7.     Send, ^c        ; Copy selected text to the clipboard.
  8.     ClipWait, 2     ; Wait for text to be put on the clipboard.
  9.    
  10.     ; Transform text.
  11.     myString := Clipboard
  12.     myString := StrReplace( myString, "  ", "§" ) ; Replace all double-spaces with a temporary section (§) character.
  13.     myString := StrReplace( myString, " ", "" )   ; Collapse remaining spaces.
  14.     myString := StrReplace( myString, "§", " " )  ; Replace temporary section (§) characters with a single space.
  15.    
  16.     Clipboard := myString ; Copy new string back to the clipboard.
  17. }
  18. Return

Contro, give the above AHK code a try and see if it works for you.  Again, this will only work if each real space is actually two spaces when your text is distorted.
« Last Edit: March 10, 2017, 04:02:37 PM by skwire »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,765
    • View Profile
    • Donate to Member
  • Select the text you want to modify.
  • Do a search for " "
  • Do a replace for ""
  • Done.

That won't work because you will replace the necessary spaces between words, too.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,570
    • View Profile
    • Donate to Member
Assuming the scenario skwire mentioned and you're using an editor that allows Search/Replace in selected text (and RegEx expressions) you could use:
Search: ( )(\S)
Replace: \2

Just make sure you only run through once otherwise it will remove all spaces on the second pass ... but then that's what Undo is for  :P

Although, you could just select each spaced out word and run the RegEx replace.

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
As I told you already, nobody can know which space to delete and which not.

I know the answer. But I keep trying : I want other answer !!!!!







 

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
Couldn't this be done with "Find and Replace"?

  • Select the text you want to modify.
  • Do a search for " "
  • Do a replace for ""
  • Done.
It's a good answer just because I can select the precise text I need to transform.
Not the spaces between words, one word once a time.
May be a manual solution, but goes well and is better than modify everything by manual.

 :-*

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
As I told you already, nobody can know which space to delete and which not.

Actually, so long as distorted text has extra spaces between ALL characters (which includes the space character), you can make this work.  Every real space will have two spaces instead of one so you can do it like this:

Code: Autohotkey [Select]
  1. #T:: ; Windows+T hotkey.  Change as desired.
  2. {
  3.     ; T h i s  i s  a  v e r y  s h o r t  s c r i p t  ; Sample of distorted text.
  4.     ;        ^^   ^^ ^^       ^^         ^^             ; Double spaces where single spaces should be.
  5.  
  6.     Clipboard := "" ; Empty the clipboard.
  7.     Send, ^c        ; Copy selected text to the clipboard.
  8.     ClipWait, 2     ; Wait for text to be put on the clipboard.
  9.    
  10.     ; Transform text.
  11.     myString := Clipboard
  12.     myString := StrReplace( myString, "  ", "§" ) ; Replace all double-spaces with a temporary section (§) character.
  13.     myString := StrReplace( myString, " ", "" )   ; Collapse remaining spaces.
  14.     myString := StrReplace( myString, "§", " " )  ; Replace temporary section (§) characters with a single space.
  15.    
  16.     Clipboard := myString ; Copy new string back to the clipboard.
  17. }
  18. Return

Contro, give the above AHK code a try and see if it works for you.  Again, this will only work if each real space is actually two spaces when your text is distorted.
Yes. That is exactly my case in this moment.

I will try and comment

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
Assuming the scenario skwire mentioned and you're using an editor that allows Search/Replace in selected text (and RegEx expressions) you could use:
Search: ( )(\S)
Replace: \2

Just make sure you only run through once otherwise it will remove all spaces on the second pass ... but then that's what Undo is for  :P

Although, you could just select each spaced out word and run the RegEx replace.
Running to try.
May be the best in short works and better the ahk script for intensive changes if necessary.
 :-*

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
As I told you already, nobody can know which space to delete and which not.





 
:tellme:

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
Assuming the scenario skwire mentioned and you're using an editor that allows Search/Replace in selected text (and RegEx expressions) you could use:
Search: ( )(\S)
Replace: \2

Just make sure you only run through once otherwise it will remove all spaces on the second pass ... but then that's what Undo is for  :P

Although, you could just select each spaced out word and run the RegEx replace.
Running to try.
May be the best in short works and better the ahk script for intensive changes if necessary.
 :-*
In pspad ?????

I think is with notepad++

 :-*

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
As I told you already, nobody can know which space to delete and which not.

Actually, so long as distorted text has extra spaces between ALL characters (which includes the space character), you can make this work.  Every real space will have two spaces instead of one so you can do it like this:

Code: Autohotkey [Select]
  1. #T:: ; Windows+T hotkey.  Change as desired.
  2. {
  3.     ; T h i s  i s  a  v e r y  s h o r t  s c r i p t  ; Sample of distorted text.
  4.     ;        ^^   ^^ ^^       ^^         ^^             ; Double spaces where single spaces should be.
  5.  
  6.     Clipboard := "" ; Empty the clipboard.
  7.     Send, ^c        ; Copy selected text to the clipboard.
  8.     ClipWait, 2     ; Wait for text to be put on the clipboard.
  9.    
  10.     ; Transform text.
  11.     myString := Clipboard
  12.     myString := StrReplace( myString, "  ", "§" ) ; Replace all double-spaces with a temporary section (§) character.
  13.     myString := StrReplace( myString, " ", "" )   ; Collapse remaining spaces.
  14.     myString := StrReplace( myString, "§", " " )  ; Replace temporary section (§) characters with a single space.
  15.    
  16.     Clipboard := myString ; Copy new string back to the clipboard.
  17. }
  18. Return

Contro, give the above AHK code a try and see if it works for you.  Again, this will only work if each real space is actually two spaces when your text is distorted.
Yes. That is exactly my case in this moment.

I will try and comment

I am doing something wrong. The hotkey don't obey me. I change T for U, but my problem continues.

 :-[

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,570
    • View Profile
    • Donate to Member
Assuming the scenario skwire mentioned and you're using an editor that allows Search/Replace in selected text (and RegEx expressions) you could use:
Search: ( )(\S)
Replace: \2

Just make sure you only run through once otherwise it will remove all spaces on the second pass ... but then that's what Undo is for  :P

Although, you could just select each spaced out word and run the RegEx replace.
Running to try.
May be the best in short works and better the ahk script for intensive changes if necessary.
 :-*
In pspad ?????

I think is with notepad++

 :-*

Works in both:

Notepad++
Search: ( )(\S)
Replace: \2

PSPad
Search: ( )(\S)
Replace: $2

2017-03-13 11_08_38.pngT h i s  i s  a  v e r y  s h o r t  s c r i p t  - This is a very short script
2017-03-13 11_11_00.pngT h i s  i s  a  v e r y  s h o r t  s c r i p t  - This is a very short script
« Last Edit: March 12, 2017, 07:12:07 PM by 4wd »

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,944
    • View Profile
    • Donate to Member
Notepad++
Search: ( )(\S)
Replace: \2

PSPad
Search: ( )(\S)
Replace: $2
Notepad++ will work just fine when using $2 for the replacement, the \2 seems to be (also) available because of a different regex library used in Notepad++ from PSPad. (PSPad won't work with \2 though).

@Contro: You still gave no answer on the question wether the original spaces between the words are there or not...

Lintalist

  • Participant
  • Joined in 2015
  • *
  • Posts: 45
    • View Profile
    • Donate to Member
If there are no double spaces for a space between words (as noted above) it probably can still be done in a "best guess" style (meaning it has to be fixed manually afterwards)

- Take a say 100K Word list (most common words in English or whatever language, these lists are available on many locations)
- Sort that by length (longest word at the top)
- Do a find/replace starting with longest word "v e r y l o n g w o r d" -> "verylongword" so it processes: tissues, issues, issue, sues, sue, is for example.
- Now you should end up with a reasonably looking sentence with some words still incorrectly jumbled, but most likely not too bad.

Worth trying (its only a few lines of code, the sorting code in AHK was already posted, do that on a Word list and a simple parsing loop should do it.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,570
    • View Profile
    • Donate to Member
@Contro: You still gave no answer on the question wether the original spaces between the words are there or not...

I think he did:

Actually, so long as distorted text has extra spaces between ALL characters (which includes the space character), you can make this work.  Every real space will have two spaces instead of one so you can do it like this:

...

Contro, give the above AHK code a try and see if it works for you.  Again, this will only work if each real space is actually two spaces when your text is distorted.

Yes. That is exactly my case in this moment.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,944
    • View Profile
    • Donate to Member
I think he did:

Well, in many cases his answer is hanging somewhere in the shades, this one still isn't quite to the point to me though I'd seen that response.

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,138
    • View Profile
    • Donate to Member
And now, how did this current challenge ended up Contro?


Would be kind of you to give any, positive or negative, feedback if your problem is solved or not.





 
« Last Edit: March 17, 2017, 03:14:33 AM by AbteriX »

Contro

  • Participant
  • Joined in 2007
  • *
  • Posts: 2,778
    • View Profile
    • Donate to Member
Yes. For me is solved.
 :-*

Best Regards

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,138
    • View Profile
    • Donate to Member
Yes. For me is solved.

And how did you solve your issue?
Which tool did you used? Which command... e.t.c ?
And, were there double spaces between the single words?