philw Posted August 7, 2008 Share Posted August 7, 2008 I'm trying to write a script that will check a block of text and capitalize the first letter of sentences if required. Something like: $str=StringRegExpReplace($teststr, "\. ([a-z])", "\. \1") except that the back-reference needs to be converted to uppercase. Is this possible? Thanks! Link to comment Share on other sites More sharing options...
Paulie Posted August 7, 2008 Share Posted August 7, 2008 (edited) StringUpper() maybe? i dunno how that would work Edited August 7, 2008 by Paulie Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 7, 2008 Moderators Share Posted August 7, 2008 (edited) Yeah, that's just not going to happen the way you have it without a loop. I thought we had a _StringProper function? Edit.. Example: $s_text = "this is a test. only to see if it works." & @CRLF & @TAB & "if it doesn't work, oh well." $s_convert = _StringProperSentence($s_text) MsgBox(0, 0, $s_convert) Func _StringProperSentence($s_string) Local $a_sre = StringRegExp($s_string, "\s*(.)(.+?\.\s*)", 3) If @error Then Return SetError(1, 0, $s_string) Local $s_hold For $i_cc = 0 To UBound($a_sre) - 1 Step 2 $s_hold &= StringUpper($a_sre[$i_cc]) & $a_sre[$i_cc + 1] Next Return $s_hold EndFunc Edited August 7, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
dhaley77 Posted August 7, 2008 Share Posted August 7, 2008 If you could use the output of the "StringUpper" function in the replace pattern, this would work great:(I added "<upper>" & "</upper>" to see what should be getting translated to uppercase)$s_text = "this is a test. only to see if it works." & @CRLF & "if it doesn't work, oh well." $s_convert = StringRegExpReplace($s_text, "(?m)(^|(\. *))([a-z])", "\2<upper>" & StringUpper("\3") & "</upper>") MsgBox(0, 0, $s_convert)This is what gets output:<upper>t</upper>his is a test. <upper>o</upper>nly to see if it works. <upper>i</upper>f it doesn't work, oh well.Dan Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 7, 2008 Moderators Share Posted August 7, 2008 If you could use the output of the "StringUpper" function in the replace pattern, this would work great: (I added "<upper>" & "</upper>" to see what should be getting translated to uppercase) $s_text = "this is a test. only to see if it works." & @CRLF & "if it doesn't work, oh well." $s_convert = StringRegExpReplace($s_text, "(?m)(^|(\. *))([a-z])", "\2<upper>" & StringUpper("\3") & "</upper>") MsgBox(0, 0, $s_convert) This is what gets output: <upper>t</upper>his is a test. <upper>o</upper>nly to see if it works. <upper>i</upper>f it doesn't work, oh well. DanYou can't use an outside function within the function. Functions are fired from right to left. So StringUpper() would fire before you even did the regular expression. Thus my statement on.. It can't be done that way. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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