name="TEST_THE_CODE"
var=$(echo $name | awk -F "THE" '{print $1 $2}')
set -- var
echo $1
echo $2
output would be
TEST_
_CODE
Thursday, January 27, 2011
Split a String in Unix
Saturday, January 22, 2011
Parsing using javascript
SAX parser links:
http://code.google.com/p/jssaxparser/
Dom parser links:
http://www.w3schools.com/Dom/dom_parser.asp
http://code.google.com/p/jssaxparser/
Dom parser links:
http://www.w3schools.com/Dom/dom_parser.asp
Degrees Minutes Seconds to Decimal Degrees
public class LongLat {
public static void main(String args[]){
double LongDouble=0;
double direction=0;
int checkDegree=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input=null;
System.out.println("Enter Longitude or Latitude");
try{
input=br.readLine().toUpperCase();
}catch(Exception e){
System.out.println("IO error");
System.exit(1);
}
Pattern p=Pattern.compile("[NEWS]");
Matcher m=p.matcher(input);
if(input.contains("N") || input.contains("E"))
direction=1;
else if(input.contains("W") || input.contains("S"))
direction=-1;
if(input.contains("N") || input.contains("S"))
checkDegree=90;
else if(input.contains("W") || input.contains("E"))
checkDegree=180;
input=m.replaceFirst("");
input=input.trim();
String[] LongDMS=input.split(" ");
if(!(Integer.parseInt(LongDMS[0])<=checkDegree)){
System.out.println("Degree should be less than "+checkDegree);
System.exit(1);
}
if(!(Integer.parseInt(LongDMS[1])<=60)){
System.out.println("Minutes should be in between 0 and "+60);
System.exit(1);
}
if(!(Integer.parseInt(LongDMS[2])<=60)){
System.out.println("Second should be in between 0 and "+60);
System.exit(1);
}
if(LongDMS.length==3)
LongDouble=Double.valueOf(LongDMS[0])+((Double.valueOf(LongDMS[1])*60)+Double.valueOf(LongDMS[2]))/3600;
LongDouble=LongDouble*direction;
System.out.println(LongDouble);
}
}
Enter Longitude or Latitude
W87 43 41
-87.72805555555556
Tuesday, January 18, 2011
Subscribe to:
Posts (Atom)