ukapu2005
asked on
Can any one provide me java code on string operations.
Can any one provide me java code for the following info.
I have a string variable 'val' that contains following info.
CUSTINFO - "1009","Kapu","Udaya","xyz ","abcd"," St Louis","USA","63146","3144 531654","" ,"uday4777 @yahoo.com "
CUSTORDR - "14501","","","300.0","C"
I would need to write java code to find the occurrences of 'CUSTORDR' from val and once it exists,
I would need to grab the value 14501 into some long variable, 300 into some float variable.
Thanks in adavance.
I have a string variable 'val' that contains following info.
CUSTINFO - "1009","Kapu","Udaya","xyz
CUSTORDR - "14501","","","300.0","C"
I would need to write java code to find the occurrences of 'CUSTORDR' from val and once it exists,
I would need to grab the value 14501 into some long variable, 300 into some float variable.
Thanks in adavance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The above program fails for the following string val. i wanted to get all occurrences of CUSTORDR. Can you please upgrade your program.
val=CUSTINFO - "1009","Kapu","Udaya","xyz ","abcd"," St Louis","USA","63146","3144 531654","" ,"uday4777 @yahoo.com "
CUSTORDR - "14501","","","300.0","C"
CUSTINFO - "1009","Kapu","Udaya","xyz ","abcd"," St Louis","USA","63146","3144 531654","" ,"uday4777 @yahoo.com "
CUSTORDR - "14502","","","400.0","C"
CUSTINFO - "1009","Kapu","Udaya","xyz ","abcd"," St Louis","USA","63146","3144 531654","" ,"uday4777 @yahoo.com "
CUSTORDR - "14503","","","500.0","C"
val=CUSTINFO - "1009","Kapu","Udaya","xyz
CUSTORDR - "14501","","","300.0","C"
CUSTINFO - "1009","Kapu","Udaya","xyz
CUSTORDR - "14502","","","400.0","C"
CUSTINFO - "1009","Kapu","Udaya","xyz
CUSTORDR - "14503","","","500.0","C"
put a loop around Stillunaware's pgm..
something like..
int indx = val.indexOf("CUSTORDR");
while (indx>=0)
{
full code
at end
val=val.substring(indx);
indx=val=val.substring(ind x);
}//end while
something like..
int indx = val.indexOf("CUSTORDR");
while (indx>=0)
{
full code
at end
val=val.substring(indx);
indx=val=val.substring(ind
}//end while
ASKER
I have given the following string
val=CUSTINFO - "1009","Kapu","Udaya","xyz ","abcd"," St Louis","USA","63146","3144 531654","" ,"uday4777 @yahoo.com "
CUSTORDR - "14501","","","300.0","C"
How were you able to get
val = "CUSTINFO - \"1009\",\"Kapu\",\"Udaya\ ",\"xyz\", \"abcd\",\ "St Louis\",\"USA\",\"63146\", \"31445316 54\",\"\", \"uday4777 @yahoo.com \"\nCUSTOR DR - \"14501\",\"\",\"\",\"300. 0\",\"C\"" ;
Is there any standard way to convert? Thanks in advance. Your help in this regard is appreciated.
val=CUSTINFO - "1009","Kapu","Udaya","xyz
CUSTORDR - "14501","","","300.0","C"
How were you able to get
val = "CUSTINFO - \"1009\",\"Kapu\",\"Udaya\
Is there any standard way to convert? Thanks in advance. Your help in this regard is appreciated.
Where do You get the string from?
If You enter it manually into Your code, than it must start and end with " character, to have this character in a middle of a string You have to escape it with backslash \"
If You enter it manually into Your code, than it must start and end with " character, to have this character in a middle of a string You have to escape it with backslash \"
This looks like homework ...
public class N {
public static void main(String[] args) {
String val = "CUSTINFO - \"1009\",\"Kapu\",\"Udaya\
long longValue = 0;
float floatValue = 0;
int indx = val.indexOf("CUSTORDR");
int startInd = 0, endInd = 0;
if (indx == -1) {
//no "CUSTORDR" in val
} else {
for(int i = indx; i < val.length(); i++) {
char c = val.charAt(i);
if (Character.isDigit(c)) {
startInd = i;
break;
}
}
for(int i = startInd; i < val.length(); i++) {
char c = val.charAt(i);
if (!Character.isDigit(c)) {
endInd = i;
break;
}
}
longValue = new Long(val.substring(startIn
for(int i = endInd; i < val.length(); i++) {
char c = val.charAt(i);
if (Character.isDigit(c) || (c == '.')) {
startInd = i;
break;
}
}
for(int i = startInd; i < val.length(); i++) {
char c = val.charAt(i);
if (!Character.isDigit(c) && !(c == '.')) {
endInd = i;
break;
}
}
floatValue = new Float(val.substring(startI
}
System.out.println("longVa
}
}