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","3144531654","","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.
ukapu2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StillUnAwareCommented:
long longValue;
float floatValue;

int indx = val.indexOf("CUSTORDR");
int startInd, endInd;
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(startInd, endInd)).longValue();
    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(startInd, endInd)).floatValue();

now longValue and floatValue contains appropriate values

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StillUnAwareCommented:
here is working sample program:

public class N {
  public static void main(String[] args) {
    String val = "CUSTINFO - \"1009\",\"Kapu\",\"Udaya\",\"xyz\",\"abcd\",\"St Louis\",\"USA\",\"63146\",\"3144531654\",\"\",\"uday4777@yahoo.com\"\nCUSTORDR - \"14501\",\"\",\"\",\"300.0\",\"C\"";
    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(startInd, endInd)).longValue();
        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(startInd, endInd)).floatValue();
    }
    System.out.println("longValue: "+longValue+"\nfloatValue: "+floatValue);
  }
}
ukapu2005Author Commented:
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","3144531654","","uday4777@yahoo.com"
CUSTORDR - "14501","","","300.0","C"
CUSTINFO - "1009","Kapu","Udaya","xyz","abcd","St Louis","USA","63146","3144531654","","uday4777@yahoo.com"
CUSTORDR - "14502","","","400.0","C"
CUSTINFO - "1009","Kapu","Udaya","xyz","abcd","St Louis","USA","63146","3144531654","","uday4777@yahoo.com"
CUSTORDR - "14503","","","500.0","C"
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

KuldeepchaturvediCommented:
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(indx);
}//end while

ukapu2005Author Commented:
I have given the following string

val=CUSTINFO - "1009","Kapu","Udaya","xyz","abcd","St Louis","USA","63146","3144531654","","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\",\"3144531654\",\"\",\"uday4777@yahoo.com\"\nCUSTORDR - \"14501\",\"\",\"\",\"300.0\",\"C\"";

Is there any standard way to convert?  Thanks in advance. Your help in this regard is appreciated.
StillUnAwareCommented:
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 \"
CEHJCommented:
This looks like homework  ...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.