What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [split] VBScript & pig latin

[split] VBScript & pig latin
Author: Message:
theimmortal_7
New Member
*


Posts: 1
Joined: Oct 2008
O.P. RE: VBScript & coding tips
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")
10-04-2008 03:11 AM
Profile E-Mail PM Find Quote Report
Jarrod
Veteran Member
*****

Avatar
woot simpson

Posts: 1304
Reputation: 20
– / Male / Flag
Joined: Sep 2006
RE: VBScript & coding tips
i'm not a fan of vb but this is my python example:P
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',



This post was edited on 10-04-2008 at 05:15 AM by Jarrod.

[Image: 5344.png]
[Image: sig.png]

A.k.a. The Glad Falconer














10-04-2008 05:14 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: VBScript & coding tips
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.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-04-2008 09:43 AM
Profile PM Find Quote Report
Jarrod
Veteran Member
*****

Avatar
woot simpson

Posts: 1304
Reputation: 20
– / Male / Flag
Joined: Sep 2006
RE: VBScript & coding tips
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

[Image: 5344.png]
[Image: sig.png]

A.k.a. The Glad Falconer














10-04-2008 09:55 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: VBScript & coding tips
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.

;)
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-04-2008 10:11 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On