Gumma Posted May 6, 2011 Posted May 6, 2011 (edited) I'm playing around with this -- I am trying to correct grammer errors automatically in paragraphs. So for instance "Hi,how are you." Or "Hi, how are you.." Those are just a few examples. I might be going about this wrong, so I thought I'd post what I'm working on and see if I can get some advise. The last part of the code fixes the grammer, but it does it everywhere. Is there a smarter way I can do this so that it actually replaces the errors correctly without breaking up each paragraph into an array or something? Local $s_string, $test, $str, $strang Local $i $s_string = "This is test,okay? Do you like me in that way,yes? Or not really??? That is,sad. Time to test,further." $str = StringRegExp($s_string,"\,\D",3) _ArrayDisplay($str) For $i = 0 to UBound($str)-1 $str[$i] = StringReplace($str[$i], ",","") Next _ArrayDisplay($str) For $i = 0 to UBound($str)-1 $strang = StringRegExpReplace ($s_string, "\,[A-z]", ", " & $str[$i], $i) MsgBox("",$i,$strang) Next Edited May 7, 2011 by Gumma
Gumma Posted May 7, 2011 Author Posted May 7, 2011 I'd delete my post but I don't know how. Figured it out. I was just a little off. For $i = 0 To UBound($str) - 1 $s_string = StringRegExpReplace($s_string, "\,[A-z]", ", " & $str[$i], 1) MsgBox("", $i, $s_string) Next
Malkey Posted May 7, 2011 Posted May 7, 2011 (edited) An example without a For-Next loop. Local $s_string = "This is a test, okay? Do you understand regular expressions,yes? Or not really???" & @CRLF & "That is,sad.. Time to test,further." $s_string = StringRegExpReplace($s_string, ",([^ ])", ", \1") ; Add a space after a coma where necessary. ;ConsoleWrite($s_string & @CRLF) If StringRegExp($s_string, "[^.]\.\.[^.]") Then $s_string = StringRegExpReplace($s_string, "(\.)\1", "\1") ; Replace two full stops only with one full stop. ConsoleWrite($s_string & @CRLF) MsgBox(0, "Results", $s_string) Edit: Changed "[^\.]\.\.[^\.]" to "[^.]\.\.[^.]". Now matches when two adjacent full stops only exists. Edited May 8, 2011 by Malkey
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