Jump to: navigation, search

"String " is a Class that is part of the generic JavaScript API. This "library" is referenced automaticaly by the browser of the OLPC station and you don't need to add anything in the program to use it.

Using functions/methods of this class you will need to create an object, a prefix.

Lets go to see an example: you have the string Abcdef and would like to isolate the first character. There are a method of the class that do it:


But you need first to create the object doing:

st = new String("Abcdef");
x =  st.charAt(0);

The value of x will be: A (the first index value is zero).

Using the prefix st - remember that you need to do the operation above - the methods of the class are:


 st.charAt(index)               Returns the single character at 
                                    position index.

 st.charCodeAt(index)           Returns the UNICODE encoding of
                                    the character at position index.

 st.concat(string2)             Returns a string conytaining
                                    string2 added to the end of 
                                    the original string.

 st.indexOf(searchValue, fromIndex)  Returns position of first 
                                    occurence of the substring 
                                    searchValue starting at
                                    index fromIndex.

                           fromIndex)   Returns position of last
                                     occurence of the substring 
                                     searchValue searching backwards 
                                     from index fromIndex. 

 this.st.slice(start, end)        Returns the substring starting 
                                      at start and ending at end.

 st.split(separator)              Returns an array of strings
                                      created by separing the original
                                      string at every occurrence 
                                      of separator.

 st.substr(start, length)          Returns a substring starting
                                       at position start and having
                                       a length of   characters.

 st.substring(index1,index2)       Returns the substring from
                                       index1 to index2.

 st.toLowerCase()                    Returns the original string
                                        with all caracters converted.

 st.toUpperCase()                    Returns the original string
                                        with all caracters converted.


st.length                           An integer representing the 
                                         number of characters in 
                                         the original string

An example of the use of this property : 

  st = new String("Abcdef");
  y = this.st.length;

The value of y will be the number : 6 


There are two courious methods that converts a string (not an object of the Class) to floating point or integer number:


Personal tools
  • Log in
  • Login with OpenID
About OLPC
About the laptop
About the tablet
OLPC wiki
In other languages