Shoutbox

headache: Special characters. - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: headache: Special characters. (/showthread.php?tid=76269)

headache: Special characters. by runarius on 07-23-2007 at 10:29 AM

I have a script which stores all my online contacts into a textfile(name,email,status and personalmessage). now, one of mye contacts(kristoffer) is using some special characters in his name, like the R with the circle around, which is causing some problems when I want to save the textfile. How do I avoid this?

Thanks


RE: headache: Special characters. by davidpolitis on 07-23-2007 at 10:47 AM

Have you tried changing the encoding of the text file to UTF-8?


RE: headache: Special characters. by runarius on 07-23-2007 at 10:49 AM

how do I do that?


RE: RE: headache: Special characters. by davidpolitis on 07-23-2007 at 10:51 AM

quote:
Originally posted by runarius
how do I do that?

Open the text document in Notepad, go to File --> Save File As.. and in the Save File As Dialog you'll see a drop-down labeled "Encoding:", select UTF-8 then save over the text document ;)
RE: headache: Special characters. by runarius on 07-23-2007 at 11:03 AM

that didn't help much.


RE: RE: headache: Special characters. by davidpolitis on 07-23-2007 at 11:05 AM

quote:
Originally posted by runarius
that didn't help much.

What do you mean by much? Didn't help at all?

Anyway, you could try Unicode encoding, sorry if I'm not really helping at all. Also, if that doesn't work, you could maybe try changing the file format...

Unless your text editor isn't displaying them properly, try opening the text document in Wordpad ;)
RE: headache: Special characters. by runarius on 07-23-2007 at 11:09 AM

tried setting it to unicode, nothing really happened. but I don't see how this could change anything, since isn't it the msn-plus-script that chooses the encoding and fileformat?

Also, the nickname I am trying to store holds alot of different odd characters. don't know which one of them causes the error.

It doesn't rally matter what the text-editor can see, I get an error in the debugger at the line where the function to store the nickname is.


RE: headache: Special characters. by davidpolitis on 07-23-2007 at 11:10 AM

the encoding affects it because if it isn't Unicode or UTF-8, the characters will just be shown as question marks...

You could also try opening the text document in Wordpad as I said above in my edited post ;)


RE: headache: Special characters. by runarius on 07-23-2007 at 11:11 AM

it doesn't get stored at all becouse of the error... all other nicknames gets stored without any problems.


RE: headache: Special characters. by davidpolitis on 07-23-2007 at 11:12 AM

Could you please post the code you're using so I can look at the functions...?

Or maybe you could just PM me all of the code so I can try to get it to work ;)


RE: headache: Special characters. by runarius on 07-23-2007 at 11:26 AM

couldn't figure out much from that... tried using it, but I cannot write those characters in the script so I have no way of searching through the string which holds the nickname in an attempt to replace the symbols by something else.

here is the code:

code:
function AddLineToFile (file, line) {
  if (!fsObj.FileExists(MsgPlus.ScriptFilesPath + '\\' + file))
    var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, 2, 1);
     else
       var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, 8, 0);
  fileObj.WriteLine(line);
  fileObj.Close();

}

I'm starting to think it is not possible to do this. Since scripts doesn't support these characters, how could it possibly save them?
RE: headache: Special characters. by davidpolitis on 07-23-2007 at 11:42 AM

You could try this, don't think it will work but its cleaner and nicer...

code:
function AddLineToFile (file, line)
{
    if (!fsObj.FileExists(MsgPlus.ScriptFilesPath + '\\' + file))
    {
            var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, 2, 1);
    }
         else
    {
               var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, 8, 0);
          fileObj.WriteLine(MsgPlus.RemoveFormatCodes(line));
          fileObj.Close();
    }
}

Also, if you wanted to just replace some characters, you could try

code:
str.replace(/CharacterToReplace/, "NewCharacter");

Sorry, don't think I can really help you anymore.
RE: headache: Special characters. by Deco on 07-23-2007 at 01:40 PM

Have you tried the RemoveFormatCodes function?
It's in the scripting documentation.
Have fun!


RE: headache: Special characters. by matty on 07-23-2007 at 01:44 PM

® is the registered trademark character it isn't a Plus! Character used for formatting.

People if you don't know what you are talking about don't post as you are only going to confuse things.

What is the error message in the debug window?

Can you post the exact name of the contact from the Contact Information Window (in a conversation type /info or from the Contact List right click the contact choose Messenger Plus! Extras > Contact Information)

My code works without a problem

code:
function OnEvent_Initialize(MessengerStart){
    //loop through the contacts
    for (var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext()){
        // write the contacts name to the file test.txt in the scripts path
        AddLineToFile ('test.txt', e.item().Name);
    }
}

function AddLineToFile (file, line) {
    // declare fsObj has FilesystemObject
    var fsObj = new ActiveXObject('Scripting.FileSystemObject');
    //check if the file exists already
    var fileexists = fsObj.FileExists(MsgPlus.ScriptFilesPath + '\\' + file);
    //open the file
    var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, (fileexists ? 8 : 1), true, (-1) /* UNICODE */);
    //try to write the name to the file
    try { fileObj.WriteLine(line); }
    catch (err) {
        //Oops we have an error lets output the name and the error
        Debug.Trace(line);
        Debug.Trace(err.description);
    }
   //close the file
    fileObj.Close();
    //unset the fsObj
    fsObj = null;
}


RE: headache: Special characters. by runarius on 07-23-2007 at 02:37 PM

tried to post his name here but just got this:

Қ®‬‬‬‬‬‬‬‭‌‍istoҒҒer


looks like alot of rubbish...  Anyway, it is suppose to spell Kristoffer, but it has a special K,R,I and F's. I figured out a way to turn them into normal characters. The only problem is I have to find a list over ALL symbols not supported and throw them into my script. hmm... sounds like a big job.


RE: headache: Special characters. by MeEtc on 07-23-2007 at 02:44 PM

code:
javascript:document.write("Қ%C2%AE‬‬‬‬‬‬‬‭‌‍istoҒҒer");
put that in the address bar to view the funky chars
RE: headache: Special characters. by runarius on 07-23-2007 at 02:57 PM

uhm... it seems that there is alot of characters inbetween the R and the I or something? wtf?


RE: headache: Special characters. by matty on 07-23-2007 at 03:56 PM

Oops matty made a mistake of his own...

code:
function OnEvent_Initialize(MessengerStart){
    //loop through the contacts
    for (var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext()){
        // write the contacts name to the file test.txt in the scripts path
        AddLineToFile ('test.txt', e.item().Name);
    }
}

function AddLineToFile (file, line) {
    // declare fsObj has FilesystemObject
    var fsObj = new ActiveXObject('Scripting.FileSystemObject');
    //check if the file exists already
    var fileexists = fsObj.FileExists(MsgPlus.ScriptFilesPath + '\\' + file);
    //open the file
    var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, (fileexists ? 8 : 2 /* Previously was set to 1 which is ForReading */), true, (-1) /* UNICODE */);
    //try to write the name to the file
    try { fileObj.WriteLine(line); }
    catch (err) {
        //Oops we have an error lets output the name and the error
        Debug.Trace(line);
        Debug.Trace(err.description);
    }
    //close the file
    fileObj.Close();
    //unset the fsObj
    fsObj = null;
}


RE: headache: Special characters. by runarius on 07-23-2007 at 04:18 PM

anybody that has a solution to this one?


RE: headache: Special characters. by Voldemort on 07-23-2007 at 04:21 PM

He corrected it already? see post above yours :p


RE: headache: Special characters. by matty on 07-23-2007 at 04:30 PM

Right here: Matty's reply to headache: Special characters.


RE: headache: Special characters. by davidpolitis on 07-25-2007 at 06:33 AM

It be more appropriate to use fsObj.CreateTextFile(MsgPlus.ScriptFilesPath + '\\' + file, true) ;)

--> Working with Files