Marius van Witzenburg We fight for our survival, we fight!

14jun/111

How to convert a string to lower case or UPPER case with Bash

Posted by mariusvw

Ever had a situation where you want the output or input in a BASH script to be lowercase or uppercase whatever happens but you couldn't find a way how to do that? You can!

Simply, use these two functions in your script:

1
2
3
4
5
6
7
8
9
10
toLower() {
  echo $1 | tr "[:upper:]" "[:lower:]" 
} 
toUpper() {
  echo $1 | tr "[:lower:]" "[:upper:]" 
}
 
# Example
echo `toUpper hey`
echo `toLower HEY`

I hope this helps you out with writing your precious script ;-)

Geëtiketeerd als: , , , , , , 1 Reactie
12jun/110

How to get parameters from query string with JavaScript

Posted by mariusvw

I don't remember where I found this piece of code, but it works nice to get query string parameters :-)

function getURLParam(strParamName) {
	var strReturn = '';
	var strHref = window.location.href;
	if (strHref.indexOf("?") > -1){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for (var iParam = 0; iParam < aQueryString.length; iParam++) {
			if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return unescape(strReturn);
}

it works quite simple, first it grabs all data after the question mark in the url, then it splits this result on the & character and then it splits again on the equal character. The result of that exists out of two pieces, the first is the key and the second the value of that key.