[split] VBScript & pig latin - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [split] VBScript & pig latin (/showthread.php?tid=86392)
RE: VBScript & coding tips by theimmortal_7 on 10-04-2008 at 03:11 AM
Maybe you guys can help me out, I'm trying to make a vbscript that uses the replace method and pattern property to takes a user's input, move the first letter of each word to the end of the word, then add a couple letters. This is what I've got, but it moves the last letter of the second word to the start of the second word. I'm stumped on this. Its supposed to translate text into pig latin.
Dim Message
Dim Title
dim result
set shellobj = CreateObject("WScript.Shell")
Message = "test"
Title = "test"
result = InputBox(Message,Title,"test", 2000, 2000)
Function ReplaceTest(patrn, replStr)
Dim regEx, str1
str1 = result
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
ReplaceTest = regEx.Replace(str1, replStr)
End Function
MsgBox(ReplaceTest("(\s+)(\S+)(\S+)", "$1$3$2") + "ay")
RE: VBScript & coding tips by Jarrod on 10-04-2008 at 05:14 AM
i'm not a fan of vb but this is my python example
hope u can learn from it
code:
word = raw_input()
if word[0] in "aeiou":
print word + "way"
else:
print word[1:] + word[:1] + 'ay',
RE: VBScript & coding tips by CookieRevised on 10-04-2008 at 09:43 AM
First of all, you forgot to set the Globel property to true. This is needed if you want to repeat the replacement for all finds and not just the first one:
regEx.Global = True
But both your pattern and replace strings are wrong though.
It should be something like this:
MsgBox (ReplaceTest("\b(\w)(\w+?)(\w)\b", "$3$2$1"))
See the description of the regular expression pattern property for VBScript:
http://www.msgpluslive.net/scripts/view/152-Windo...ipt-Documentation/
But note that it will not work properly if your words begin or end with other letters than the standard ones or with accents and stuff, eg: ö ô é, etc
-------
Also note that always replacing the first and last letter and adding "ay" isn't pig-latin.
Also the example shown by Jarrod isn't pig latin. Although it comes very close. There are more rules than just swapping the letters and adding "ay"
@Jarrod: Python works completely different and isn't going to help with VBScript in this case.
RE: VBScript & coding tips by Jarrod on 10-04-2008 at 09:55 AM
quote: Originally posted by CookieRevised
Also note that always replacing the first and last letter and adding "ay" isn't pig-latin.
Also the example shown by Jarrod isn't pig latin. Although it comes very close. There are more rules than just swapping the letters and adding "ay"
quote: Originally posted by wiki
For words that begin with vowel sounds (including silent consonants), simply add the syllable "ay" to the end of the word. In some dialects, to aid in pronunciation, an extra consonant is added to the beginning of the suffix; for instance, Eagle could be eagle'yay, eagle'way, eagle'hay, or something similar
i know python is different, but the method may be of use, i mean hey its all code
RE: VBScript & coding tips by CookieRevised on 10-04-2008 at 10:11 AM
There are special cases like words starting with "q", IIRC.
Your code did help in understanding how pig latin works (provided you understand Python code ofcourse), but it doesn't help in actually coding it in VBScript.
The pyhton code isn't much help in the sense that python code is different than vbscript, especially when it comes down to manipulating strings (eg: individual letters of words). Python is closer to J(ava)Script. Manipulating strings in VBScript is done in a completely different way than in Python. The method you showed simply doesn't exist in VBScript.
(eg: You could also have shown an ASM routine doing pig lating. It would have been similar as it shows how pig latin works, but doesn't show you how in VBScript.)
Anyways, I wouldn't personaly use regular expressions for doing Pig Latin as the regular expression engine in VBScript is a bit wobbly when it comes down to accented letters and stuff (which you should take into account IMHO. Or at least convert them to non-accented letters first for true pig latin). If all you're using are letters A-Za-z0-9 then it should be fine though.
|