Text functions
//////////////////////////////////////////////////////////////////////////////
// FILE: txt.js
// PURPOSE: Text functions
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function TxtArg(url, // Url, query string
nam) // Arg name
// PURPOSE: Returns an argument from a query string (url).
//////////////////////////////////////////////////////////////////////////////
{
var val = TxtBetween2Tag(url+"&", nam+"=", "&");
return(val);
};
//////////////////////////////////////////////////////////////////////////////
function TxtBetween2Tag(inpTxt, // Text
tagIni, // Initial tag
tagEnd) // End tag
// PURPOSE: The simplest TxtBetween2Tag(), no case sensitive, mandatory and
// no compact. .substring(i,e) stops at position e and does not
// include the character at position e.
//////////////////////////////////////////////////////////////////////////////
{
var txtBet = "";
var posIni = inpTxt.indexOf(tagIni);
if(posIni >= 0) // If tagIni found
{
var lenIni = tagIni.length;
var posSub = posIni + lenIni;
var posEnd = inpTxt.indexOf(tagEnd, posSub);
if(posEnd >= posSub) { txtBet = inpTxt.substring(posSub,posEnd); }
}
return(txtBet);
};
//////////////////////////////////////////////////////////////////////////////
function TxtHex(txt) // Text
// PURPOSE: Returns true if is 0123456789ABCDEF.
//////////////////////////////////////////////////////////////////////////////
{
var len = txt.length;
var dig = false;
var alf = false;
var res = false;
if(len == 1 && txt >= "0" && txt <= "9" ) { res = true; }
else if(len == 1 && txt >= "A" && txt <= "F" ) { res = true; }
return(res);
}
//////////////////////////////////////////////////////////////////////////////
function TxtMix(txt, // Text
pos) // Position
// PURPOSE: Returns the modified text (abcdef,2)->cdefab.
//////////////////////////////////////////////////////////////////////////////
{
var len = txt.length;
var res = txt;
if(len > pos) { res = txt.substr(pos,len-pos) + txt.substr(0,pos); }
return(res);
}
//////////////////////////////////////////////////////////////////////////////
function TxtReplace(inpTxt, oldTxt, newTxt)
// PURPOSE: Returns a text with oldTxt change by newTxt. Does not use
// regular expressions.
//////////////////////////////////////////////////////////////////////////////
{
var tmpArr = inpTxt.split(oldTxt);
return(tmpArr.join(newTxt));
}
//////////////////////////////////////////////////////////////////////////////
function TxtReplaceTable(str, // String
tab) // Table with pairs (oldTxt, newTxt)
// PURPOSE: Returns a strings with all the replacements applied in order.
//////////////////////////////////////////////////////////////////////////////
{
for(var pos=0; pos<tab.length; pos++)
{
str = TxtReplace(str, tab[pos][0], tab[pos][1]);
}
return(str);
}
//////////////////////////////////////////////////////////////////////////////
function TxtSel(str, // String
fun) // Select funtion
// PURPOSE: Returns the string of chars of str that fun(chr) is true.
//////////////////////////////////////////////////////////////////////////////
{
var sel = ""; // String of selected elements
for(var pos=0; pos<str.length; pos++)
{
var chr = str.substr(pos,1); // One char
if(fun(chr)) { sel = sel + chr; }
}
return(sel);
}
Ediciones.aContracorriente construye las páginas del sitio web edicionesacontracorriente.com
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio