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 

Dots among numbers
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Farmer
Guest





PostPosted: Sat Jan 23, 2010 11:47 am    Post subject: Dots among numbers Reply with quote

Can someone help me with this please?

I have a lot of documents I need to edit, I already figured out alot of what I need to do using ahk but not this one, all I need is to replace spaces among numbers with dots, and make the first word that comes after this sign - start with a capital letter, example:

From this:
Nathaniel Branden 09 04 1930 - the first step toward change is awareness. The second step is acceptance.
Nathaniel Branden

To this:
Nathaniel Branden 09.04.1930 - The first step toward change is awareness. The second step is acceptance.
Nathaniel Branden

Hope someone can help
Back to top
dmatch



Joined: 15 Oct 2007
Posts: 252

PostPosted: Sat Jan 23, 2010 3:58 pm    Post subject: Reply with quote

Try something like this:

Code:
Test=
(
Nathaniel Branden 09 04 1930 - the first step toward change is awareness.
The second step is acceptance.
Nathaniel Branden
)
OutTest:=Test
length:=strLen(Test)
pos:=InStr(Test, " - ")
if(pos){
   OutTest:=""
   DateStart:=pos-10 ;Assumes Date always preceeds the first " - "
   ;Get 1st part of string
   OutTest:=SubStr(Test,1,DateStart-1)
   ;Get date part of string
   TextToChange:=SubStr(Test,DateStart,pos-DateStart)
   ;Change spaces in date to a .
   StringReplace, TextToChange, TextToChange, %A_Space%, ., All
   ;Add date and " - " to Output string
   OutTest:=OutTest . TextToChange . " - "
   CharToGoUpper:=SubStr(Test, pos+3, 1) ;Get 1st char after " - "
   StringUpper, CharToGoUpper, CharToGoUpper ;make uppercase
   ;Add rest of string
   OutTest:=OutTest . CharToGoUpper . SubStr(Test, pos+4, length-pos-1)
}
MsgBox, %OutTest%
ExitApp
I am sure there are other ways to accomplish this but hope this helps.

dmatch
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Sat Jan 23, 2010 4:18 pm    Post subject: Reply with quote

Code:
var =
(
Nathaniel Branden 09 04 1930 - the first step toward change is awareness. The second step is acceptance.
Nathaniel Branden
)
MsgBox,% RegExReplace(var,"(\d) (\d\d) (\d{4} - )([a-z]?)","$1.$2.$3$U4")
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sat Jan 23, 2010 4:19 pm    Post subject: Re: Dots among numbers Reply with quote

I love RegEx...

Code:
input=
(LTrim
   Nathaniel Branden 09 04 1930 - the first step toward change is awareness.
   The second step is acceptance.
   Nathaniel Branden
)
regex=(\d{2})\s(\d{2})\s(\d{4})(\s-\s)(.)
replace=$1.$2.$3$4$u5
output:=RegExReplace(input, regex, replace)
msgbox, 64, , ---input---`n%input%`n`n---output---`n%output%
Back to top
Farmer
Guest





PostPosted: Sat Jan 23, 2010 10:37 pm    Post subject: Reply with quote

Thanks guys, but its not working like I want Sad, I want to highlight the text and use a hotkey to do the rest, this is what I tried but no luck? Any idea?
Code:

F1::
Send,^x
ClipWait,1
string=%clipboard%
string := RegExReplace(string,"(\d) (\d\d) (\d{4} - )([a-z]?)","$1.$2.$3$U4")
clipboard=%string%
Send,^v
Return
Back to top
closed



Joined: 07 Feb 2008
Posts: 509

PostPosted: Sun Jan 24, 2010 8:27 am    Post subject: Reply with quote

Can you elaborate what is not working?

I just tried it and it seems to work.My first try was in PSPad but there the F1 did not function ( greedily used by PSPad) but in a sticky note it worked.


This is what was entered:
Quote:
Nathaniel Branden 09.04.1930 - The first step toward change is awareness.
The second step is acceptance.
Nathaniel Branden
Back to top
View user's profile Send private message
Farmer
Guest





PostPosted: Sun Jan 24, 2010 9:00 am    Post subject: Reply with quote

Well, I want it to work on whatever I have on my clipboard and not to whats between
(
....
)

I tried modifying it as in my last post, no luck Sad
Back to top
closed



Joined: 07 Feb 2008
Posts: 509

PostPosted: Sun Jan 24, 2010 9:25 am    Post subject: Reply with quote

I am sorry but i can still not see where it goes wrong.Can you give some example of something put on your clipboard that does not work?

Does the program only works with the example given here in your first post?

I can see it only works if the date is always the same format.Or does it change parts that must not be changed in some texts?
Back to top
View user's profile Send private message
Farmer
Guest





PostPosted: Sun Jan 24, 2010 9:35 am    Post subject: Reply with quote

Ohhh, so it was made to work with that example only? Confused

I just gave that as an example, if you read my first post then you will see, I even said "I have a lot of documents.."

I have something like 2000 pages to go through, and that's why I want it to work on whatever I have in clipboard.

Ideas Question
Back to top
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Sun Jan 24, 2010 10:03 am    Post subject: Reply with quote

Here's another regex you can try:

Code:
var=
(
Nathaniel Branden 09 04 1930 - the first step toward change is awareness. The second step is acceptance.
Nathaniel Branden
)

MsgBox % RegExReplace(var,"(\d+) (\d+) (\d+) - (\w+)","$1.$2.$3 - $T4")

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Farmer
Guest





PostPosted: Sun Jan 24, 2010 10:38 am    Post subject: Reply with quote

I'm almost crying Sad

I really appreciate you trying to help, but it seems I made a mistake by giving that example in the first place.
I just want it to work on clipboard and NOT that specific example Confused

Please can someone make it work on clipboard content?
As I said, I have to go through 2000 pages of text, so I need to highlight the text I need to edit, and a hotkey will do the rest
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Jan 24, 2010 10:41 am    Post subject: Reply with quote

Just replace var with clipboard
Code:
RegExReplace(clipboard,...
if you want to change the clipboard contents:
Code:
clipboard:=RegExReplace(clipboard,...

_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Farmer
Guest





PostPosted: Sun Jan 24, 2010 11:04 am    Post subject: Reply with quote

Sad

Guys, this will only work on that example I gave and it wont work on anything else, it wont even work on the same example if I add few numbers to it, so the guys who posted here misunderstood. And I don't know RegEx so I can't edit it to work on different content of the clipboard.

I tried this code on the example I gave and it works, I tried it on other lines and it wont, so please someone test it and help me

This iis the script:

Code:
^1::
Send,^x
ClipWait,1
string=%clipboard%
string:= RegExReplace(string,"(\d) (\d\d) (\d{4} - )([a-z]?)","$1.$2.$3$U4")
clipboard=%string%
Send,^v
Return



I'm crying now Sad
Back to top
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Sun Jan 24, 2010 11:47 am    Post subject: Reply with quote

This example the code works so something is different with your clipboard data not with the script
Code:
clipboard=
(
Nathaniel Branden 09 04 1930 - the first step toward change is awareness. The second step is acceptance.
yada yaa 12 12 1984 - lorum ipsum
yeeeeeeeeeea baby 06 08 2001 - keep on rocking in the free world
)

MsgBox % RegExReplace(clipboard,"(\d+) (\d+) (\d+) - (\w+)","$1.$2.$3 - $T4")
You can work directly with the clipboard loose the 'string' variable, perhaps your clipboard doesn't have the correct data, did you think about that ?
Code:

^1::
Send,^x
ClipWait,1
MsgBox % "Before:`n" Clipboard
clipboard:= RegExReplace(clipboard,"(\d+) (\d+) (\d+) - (\w+)","$1.$2.$3 - $T4")
MsgBox % "After:`n" Clipboard
;Send,^v
Return


Why do you need to do it with the clipboard? Almost ANY decent text editor (not notepad) can do this for you without the need to select or copy data to the clipboard.
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Farmer
Guest





PostPosted: Sun Jan 24, 2010 12:25 pm    Post subject: Reply with quote

I just tried it and it wont work on the following line:

this is a test - file 3 3 3 77 6 54 4 5 6 7, please - help me

So I don't know what I'm doing wrong

Is it possible to split the two functions? So one will look for numbers and replace spaces among them with dots, and another function will make the word that comes after - start with a capital letter
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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