Krishnan B
Krishnan B

Reputation: 101

How to extract values from a string

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..

Upvotes: 1

Views: 561

Answers (2)

Pritam Karmakar
Pritam Karmakar

Reputation: 2801

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]);

Upvotes: -1

WhiteFang34
WhiteFang34

Reputation: 72079

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();

Upvotes: 9

Related Questions