﻿//string funktionen
//trim: Strip whitespace from the beginning and end of a string
function trim(str)
{ 
	var reg = /[ \t\n\r]/;
	while(str.charAt(0).match(reg))
	{
		str = str.substr(1,(str.length-1));
	}
	while(str.charAt(str.length-1).match(reg))
	{
		str = str.substr(0,(str.length-2));
	}
	return str;
}

//replace string hits with repl using regExp.. u can use $n as backreference
function pregReplace(strRegExp, repl, str)
{
	var result = false;
	var regExp = new RegExp(strRegExp);
	result[i] = str.replace(regExp, repl);
	return result;
}

//replace all array-string-objects hits in arr with repl using regExp.. u can use $n as backreference
function arrPregReplace(strRegExp, repl, arr)
{
	var result = new Array();
	var regExp = new RegExp(strRegExp);

	if(arr[0])
	{
		for(var i=0;i<arr.length;i++)
		{		
			result[i] = arr[i].replace(regExp, repl);
		}
	}
	return result;
}

//return an array with all arr-string-objects that matched the reg. expr.
function arrPregMatch(strRegExp, repl, arr)
{
	var result = new Array();
	var regExp = new RegExp(strRegExp);

	if(arr[0])
	{
		for(var i=0;i<arr.length;i++)
		{
			if(arr[i].match(regExp, repl))
				result[i] = arr[i];
		}
	}
	return result;
}