skannar streng og finnur tákn!!! var myString = "Have a nice day!"; var index = myString.indexOf("a"); while (index != -1) { alert(index); index = myString.indexOf("a", index + 1); // start search after last match found } // Copyright (C) 2001. Gabriel Weinberg, // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public // License along with this library (license.txt); if not, write to the // Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, // MA 02111-1307 USA // This source file is called oj.string.js and is part of the // Open JavaScript library available at // This function deletes non-breaking spaces from a given string. function deleteNbsp(str) {return replaceString(' ',' ',str);} // This function replaces breaking spaces with non-breaking spaces // for a given string. function replaceNbsp(str) {return replaceString(' ',' ',str);} // This function deletes the whitespace from a given string. function deleteSpacing(str) {return replaceString(' ','',str);} // This function turns a given string into a javaName, which is a // string with no spaces where the first letter of the first word is // lower case and the first letter of each subsequent word is upper case. function javaName(str) { // First trim the string. str = trim(str); // Get an array of the words. var word = str.split(' '); // For each word. for (var i=0; i 0) && ( (str.charAt(end-1) == ' ') || (str.charAt(end-1) == '\n') || (str.charAt(end-1) == '\r') || (escape(str.charAt(end-1))=='%A0') || (str.charAt(start) == escape(' ')) ) ) --end; // If all whitespace, return the null string. if (start>end) {return "";} // Else return the subtring that isn't whitespace. else {return str.substring(start, end);} return true;} // This function converts a given string to uppercase. function upper(str) {return str.toUpperCase();} // This function truncates a given string to a given length. function truncate(str,length){ if(str.length && str.length>length) return str.substr(0,length); }