function Left(str, n){
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
function Right(str, n){
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}
//Devuelve la cadena en minúsculas
function LCase(Value) {
return Value.toString().toLowerCase();
}
//Devuelve la cadena en mayúsculas
function UCase(Value) {
return Value.toString().toUpperCase();
}
//Devuelve la longitud de la cadena
function Len(Expression) {
return Expression.toString().length;
}
//Elimina de una cadena dada los espacios tanto de la derecha como de la izquierda
function trim(str)
{
return str.replace(/^\s*|\s*$/g,"");
}
function Mid(Str, Start, Length) {
if (Length < 1) {
return "";
}
if (Start < 0) {
return "";
}
return Str.substring(Start, Start + Length);
}
function InStr(Start, String1, String2, Compare) {
if (Start < 1) {
return "";
}
if (Start > Len(String1)) return 0;
if (Len(String2) == 0) return Start;
if (Compare == 1) {String1 = LCase(String1); String2 = LCase(String2);}
if (Start > 1) {
var index = Right(String1, Len(String1) - Start + 1).indexOf(String2)
if (index == -1) {return 0;} else {return index + Start;}
} else {
return String1.indexOf(String2) + 1
}
}
function InStrRev(StringCheck, StringMatch, Start, Compare) {
if (Start == 0 || Start < -1) {
return "";
}
if (Len(StringMatch) == 0) return Start;
if (Compare == 1) {
StringCheck = LCase(StringCheck); StringMatch = LCase(StringMatch);
}
if (Start > 1) {
return Left(StringCheck, Start).lastIndexOf(StringMatch) + 1;
} else {
return StringCheck.lastIndexOf(StringMatch) + 1;
}
}
//Esta funcion es igual que el stringbuilder de .NET
function StringBuilder(sString) {
// public
this.length = 0;
this.append = function (sString) {
// append argument
this.length += (this._parts[this._current++] = String(sString)).length;
// reset cache
this._string = null;
return this;
};
this.toString = function () {
if (this._string != null)
return this._string;
var s = this._parts.join("");
this._parts = [s];
this._current = 1;
this.length = s.length;
return this._string = s;
};
// private
this._current = 0;
this._parts = [];
this._string = null; // used to cache the string
// init
if (sString != null)
this.append(sString);
}