473,408 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Pls help me out to separate the given String !!!

4
Given String:-
ST200STT:35697600114106009,20070407,08:09:00,+18.5 11246,+73.842756,1.430,332.87,1,0000,0

I wanna separate this string in the format below,pls help me out...

35697600114106009 = unit ID

20070407 = date

08:09:00 = Time(GMT)

+18.511246 = Latitude

+73.842756 = Longitude

1.430 = Speed

332.87 = heading

How can it be done by using String Tokenizer???
Jul 10 '07 #1
10 1905
JosAH
11,448 Expert 8TB
Given String:-
ST200STT:35697600114106009,20070407,08:09:00,+18.5 11246,+73.842756,1.430,332.87,1,0000,0

I wanna separate this string in the format below,pls help me out...

35697600114106009 = unit ID

20070407 = date

08:09:00 = Time(GMT)

+18.511246 = Latitude

+73.842756 = Longitude

1.430 = Speed

332.87 = heading

How can it be done by using String Tokenizer???
Don't use a String Tokenizer, have a look at the String.split() method instead.

kind regards,

Jos
Jul 10 '07 #2
mandyj
4
Pls help me out,i dont much about it...

Don't use a String Tokenizer, have a look at the String.split() method instead.

kind regards,

Jos
Jul 10 '07 #3
JosAH
11,448 Expert 8TB
Pls help me out,i dont much about it...
Well, I don't much about it either but reading the documentation helps me quite a bit.

kind regards,

Jos
Jul 10 '07 #4
mandyj
4
Anyone has a solution code,pls send it to me,Thanks for the help Josah..Bye...
Regards,
Mandy !!!
Jul 10 '07 #5
JosAH
11,448 Expert 8TB
Anyone has a solution code,pls send it to me,Thanks for the help Josah..Bye...
Regards,
Mandy !!!
First read this and then try this:

Expand|Select|Wrap|Line Numbers
  1. String s= // your string
  2. String[] parts= s.split(",");
  3. for (int i= 0; i < parts.length; i++)
  4.   System.out.println("parts["+i+"]= "+parts[i]);
  5.  
kind regards,

Jos

ps. adding a bunch of exclamation marks won't help.
Jul 10 '07 #6
[quote=JosAH]First read this and then try this:

Expand|Select|Wrap|Line Numbers
  1. String s= // your string
  2. String[] parts= s.split(",");
  3. for (int i= 0; i < parts.length; i++)
  4.   System.out.println("parts["+i+"]= "+parts[i]);
  5.  
QUOTE]
hello JosAH
i think first u have to add this line!!!

Expand|Select|Wrap|Line Numbers
  1. //after String s = "" //ur string.
  2. s=s.substring(0,s.indexOf(":"));
  3.  
because split() will work using " , " and will consider the xxxx:1234, as one part!
am i right?

thanks
Jul 11 '07 #7
r035198x
13,262 8TB
because split() will work using " , " and will consider the xxxx:1234, as one part!
am i right?

thanks
Isn't that what the OP wants? i.e to have xxxx:1234 as one part?
Jul 11 '07 #8
Hi,
If the Variables are fix in length, then you can use the following code :


String str = "ST200STT:35697600114106009,20070407,08:09:00,+18. 511246,+73.842756,1.430,332.87,1,0000,0";
System.out.println("unit ID is :"+str.substring(8,26));
System.out.println("Date is :"+str.substring(27,35));
System.out.println("Time in GMT is :"+str.substring(36,44));
System.out.println("Latitude is :"+str.substring(45,55));
System.out.println("Longitude is :"+str.substring(56,66));
System.out.println("Speed is :"+str.substring(67,72));
System.out.println("Heading is :"+str.substring(73,79));

Cheers,
Sateesh.
Jul 13 '07 #9
JosAH
11,448 Expert 8TB
Hi,
If the Variables are fix in length, then you can use the following code :


String str = "ST200STT:35697600114106009,20070407,08:09:00,+18. 511246,+73.842756,1.430,332.87,1,0000,0";
System.out.println("unit ID is :"+str.substring(8,26));
System.out.println("Date is :"+str.substring(27,35));
System.out.println("Time in GMT is :"+str.substring(36,44));
System.out.println("Latitude is :"+str.substring(45,55));
System.out.println("Longitude is :"+str.substring(56,66));
System.out.println("Speed is :"+str.substring(67,72));
System.out.println("Heading is :"+str.substring(73,79));

Cheers,
Sateesh.
*yuck* never put magic numbers in your program code(*). It isn't needed here,
a simple String.split(":") does most if not all of the work.

kind regards,

Jos

(*) according to my holy book of rules of thumb; this is rule #4356345234765 ;-)
Jul 13 '07 #10
r035198x
13,262 8TB
Hi,
If the Variables are fix in length, then you can use the following code :


String str = "ST200STT:35697600114106009,20070407,08:09:00,+18. 511246,+73.842756,1.430,332.87,1,0000,0";
System.out.println("unit ID is :"+str.substring(8,26));
System.out.println("Date is :"+str.substring(27,35));
System.out.println("Time in GMT is :"+str.substring(36,44));
System.out.println("Latitude is :"+str.substring(45,55));
System.out.println("Longitude is :"+str.substring(56,66));
System.out.println("Speed is :"+str.substring(67,72));
System.out.println("Heading is :"+str.substring(73,79));

Cheers,
Sateesh.
Why waste your time doing manually what the split method does automatically?
Jul 13 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Roberto Becerril | last post by:
Hi forum, i'm a little new in javascript and maybe you can help me. I have an html form and an icon, if i click on the icon, a new pop-up window is open and shows a list of numbers with a...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
12
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is...
1
by: lqnt1981 | last post by:
Following is the code in python that opens all files under a directories and puts a comma in place of whitespace, I can see the output on the command line, but I am not sure what to do in order to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.