AutoHotkey Community

It is currently May 27th, 2012, 1:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Dots among numbers
PostPosted: January 23rd, 2010, 12:47 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2010, 4:58 pm 
Offline

Joined: October 15th, 2007, 7:23 pm
Posts: 252
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2010, 5:18 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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")


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Dots among numbers
PostPosted: January 23rd, 2010, 5:19 pm 
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%


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2010, 11:37 pm 
Thanks guys, but its not working like I want :(, 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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 9:27 am 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 10:00 am 
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 :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 10:25 am 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 10:35 am 
Ohhh, so it was made to work with that example only? :?

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 :?:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 11:03 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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")

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 11:38 am 
I'm almost crying :(

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 :?

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 11:41 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Just replace var with clipboard
Code:
RegExReplace(clipboard,...
if you want to change the clipboard contents:
Code:
clipboard:=RegExReplace(clipboard,...

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 12:04 pm 
:(

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 :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 12:47 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2010, 1:25 pm 
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


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], engunneer, JSLover, sjc1000 and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group