Search Unity

charCodeAt() Support..

Discussion in 'Scripting' started by klindeman, Sep 20, 2005.

  1. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    I am trying to access the charCodeAt(index) function, part of JS. Is there no way to get to the built in Javascript functions, or is there a comparable function built into mono?

    The function takes a character at the index, and changes it to the unicode character code...
     
  2. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    Oh, wait. Nevermind. Noticed I was using the function wrong. needs to be like:

    Code (csharp):
    1. var myString ="bobobobo";
    2. myString.charCodeAt(0);
    3.  
    Instead of trying to find it in System.* :oops:

    /* Edit */
    err, maybe my quetsion is still valid. I tried that and it says "System.MissingMethodException: Cannot find method charCodeAt"
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Code (csharp):
    1.  
    2. myString[0]
    3.  
     
  4. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    I would have swore I tried that and I couldn't seem to get anything out of it...

    I shall try that later today.
     
  5. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    Normally I would have expected doing something like:

    Code (csharp):
    1. if (name[a] == 'a')
    would work (note single quotes)... Seems to generate a compiler error. (Unexpected char).

    // Edit
    Talked to aarku, and he said to try doing it like this:

    Code (csharp):
    1. if (name[a] == "a"[0])
    Which again, didn't work. It spat out the error: "Operator == cannot be used with a left hand side type of System.Object and a right hand side of type System.Char"

    So he suggested that I just make a char buffer that I store name[a] in first, and then check if they are ==, which worked.