The previous two days quoted string out of bounds, found in the lookup, should be to take the position of a certain character, error, the original use of LastIndexOf to get this character in the search string is not.
Workaround, before taking the position, verify that the character exists.
if (Name.lastindexof ("Form")!=-1) {
Name = name.substring (0, Name.lastindexof ("Form"));
}
JScript Language Reference
--------------------------------------------------------------------------------
LastIndexOf method
Returns the last occurrence of the substring of a string object.
Strobj.lastindexof (substring[, startindex])
Parameters
Strobj
Required option. A String object or text.
Substring
Required option. The substring to find within the string object.
startindex
Options available. The integer value indicates the starting index position of the lookup within the String object. If omitted, the lookup starts at the end of the string.
Description
The LastIndexOf method returns an integer value that indicates the starting position of the substring of the string object. If no substring is found, returns-1.
If the startindex is a negative number, the startindex is treated as zero. If it is larger than the maximum character position index, it is considered to be the largest possible index.
Performs a lookup from right to left. Otherwise, the method is the same as indexOf.
The following example illustrates the use of the LastIndexOf method:
function Lastindexdemo (STR2)
{
var str1 = "Babebibobubabebibobu"
var s = str1.lastindexof (STR2);
return (s);
}
Used in Java classes, roughly the same.
The following excerpt from http://www.chinageren.com/jc/HTML/115914_2.html
Datebean.java
{
Private String datestr;
Private String year;
Private String Month;
Private String Day;
//
Set method for public void Setdatestr (String str)//Private variable Datestr
{
THIS.DATESTR=STR;
}
Public String Getdatestr ()///Private variable Datestr get method
{
return datestr;
}
public string getyear ()//Getting year strings
{
int A=datestr.indexof ("-");//Find the number of digits of the first "-"
Year=datestr.substring (0,a);//A string before the first "-"
return to year;
}
The public string getmonth ()//Gets the month strings
{
int A=datestr.indexof ("-");//Find the number of digits of the first "-"
int B=datestr.lastindexof ("-");//Find the Last "-" number of digits
Month=datestr.substring (a+1,b);//Take Two "-" string
Return month;
}
public string Getday ()//Getting Day strings
{
int B=datestr.lastindexof ("-");//Find the Last "-" number of digits
int len=datestr.length ()//length of string
Day=datestr.substring (B+1,len);//Take the Last "-" string
Return day;
}
}