1

I am doing one media player in java, there I need to extract values from the string "01:23:02" as int x=01,y=23,z=02 for seek operation..

1
  • Note that its impossible to get 01 02 ints, do you want x="1" y="23" z="2" ints or strings x="1" y="23" z="2" Commented May 5, 2011 at 6:55

2 Answers 2

9

Here's one way to do it since you want int values:

Scanner scanner = new Scanner("01:23:02").useDelimiter(":");
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
Sign up to request clarification or add additional context in comments.

1 Comment

he also asked for 01/02, you are right about 01 being impossible for an int, I had a brain fart.
-1

This is using C#

        string time = "01:23:02";
        string[] str = time.Split(':');
        int x = Convert.ToInt16(str[0]);
        int y = Convert.ToInt16(str[1]);
        int z = Convert.ToInt16(str[2]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.