What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Request] In / Out Text Replacer

[Request] In / Out Text Replacer
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: [Request] In / Out Text Replacer
quote:
Originally posted by roflmao456
* roflmao456 calls Cookie to explain :P
Whooosh..

For things like this many people use the Replace function. But the replace function will search for the stuff to replace from the beginning of the text you paste to it.

So, in a list if you have the letters A B C D E F G H and you're going to replace each letter respectivly with C D E F G H A B... Then you can (and will) come in the situation like this:

The next pseudo code is almost always used in scripts like this (you can verify this in the scripting database). But it will, in most cases, render wrong results:

var myword = "ABC"
myword = myword.replace("A", "C")
myword = myword.replace("B", "D")
myword = myword.replace("C", "E")
myword = myword.replace("D", "F")
myword = myword.replace("E", "G")
myword = myword.replace("F", "H")
myword = myword.replace("G", "A")
myword = myword.replace("H", "B")

myword is now "EBC"(1) or "ABA"(2) not "CDE" as it was intended!

This because:

(1) if Replace replaced the first letter it finds (like it does by default):

var myword = "ABC"
myword = myword.replace("A", "C") => myword is now "CBC"
myword = myword.replace("B", "D") => myword is now "CDC"
myword = myword.replace("C", "E") => myword is now "EDC" (here the first error occurs)
myword = myword.replace("D", "F") => myword is now "EFC"
myword = myword.replace("E", "G") => myword is now "EFC"
myword = myword.replace("F", "H") => myword is now "EHC"
myword = myword.replace("G", "A") => myword is still "EHC"
myword = myword.replace("H", "B") => myword is now "EBC"

or, (2) if Replace replaced all the letters it finds:

var myword = "ABC"
myword = myword.replace("A", "C") => myword is now "CBC"
myword = myword.replace("B", "D") => myword is now "CDC"
myword = myword.replace("C", "E") => myword is now "EDE" (here the first error occurs)
myword = myword.replace("D", "F") => myword is now "EFE"
myword = myword.replace("E", "G") => myword is now "GFG"
myword = myword.replace("F", "H") => myword is now "GHG"
myword = myword.replace("G", "A") => myword is now "AHA"
myword = myword.replace("H", "B") => myword is now "ABA"

Conclussion: never ever use:

var myword = "something"
myword = myword.replace("A", "B")
myword = myword.replace("B", "C")
myword = myword.replace("C", "A")

or the likes (like looping using a list, as this is just the same, only shorter in code) to replace text when the text to search for contains the same characters as the text to replace with!

;)


-------------------------

quote:
Originally posted by Yukai
But why FirstWord and SecondWord? Are they linked with Kanjiword and SecondKanjiWord?

Let's say that:

FirstWord gets changed to A
KanjiWord gets changed to B

Will "A" then become "B" when i type and will an incoming "B" become "A"?
yep

But only if Kanji and Romaji don't have any words in common (or even parts of words!!). Otherwise you will have the situation as described above. Which means you will not be able to use that script for this.

Though, there are other situations in which this script will not work properly and this has got something to do with the RecievedMessage event and detecting if the recieved message is/isn't a message you wrote. But that's explained in another thread ;)

And then there is also the fact that you can not return a longer message than the one you've recieved in the RecievedMessage event. Which can and will also lead to this script not working properly in those cases.

-------------------------

This said, it could be possible that there is a Windows API which already does this convertion, I can't remember anymore, I'll need to look this up (unless someone else can confirm this or not). > EDIT: after an extremely quick plain search I can't find any api for this though...

This post was edited on 06-25-2007 at 04:04 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-25-2007 03:24 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Request] In / Out Text Replacer - by Yukai on 06-24-2007 at 06:01 PM
RE: [Request] In / Out Text Replacer - by toddy on 06-24-2007 at 06:07 PM
RE: [Request] In / Out Text Replacer - by Yukai on 06-24-2007 at 06:12 PM
RE: [Request] In / Out Text Replacer - by roflmao456 on 06-24-2007 at 07:32 PM
RE: RE: [Request] In / Out Text Replacer - by Yukai on 06-24-2007 at 07:47 PM
RE: RE: RE: [Request] In / Out Text Replacer - by Deco on 06-24-2007 at 09:46 PM
RE: [Request] In / Out Text Replacer - by Yukai on 06-24-2007 at 10:36 PM
RE: [Request] In / Out Text Replacer - by roflmao456 on 06-25-2007 at 02:46 AM
RE: RE: [Request] In / Out Text Replacer - by CookieRevised on 06-25-2007 at 03:24 AM
RE: [Request] In / Out Text Replacer - by Yukai on 06-25-2007 at 11:18 AM
RE: [Request] In / Out Text Replacer - by CookieRevised on 06-25-2007 at 11:32 AM
RE: [Request] In / Out Text Replacer - by Yukai on 06-25-2007 at 12:31 PM
RE: [Request] In / Out Text Replacer - by markee on 06-26-2007 at 02:10 PM


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