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???
10 1905
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
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
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
Anyone has a solution code,pls send it to me,Thanks for the help Josah..Bye...
Regards,
Mandy !!!
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: -
String s= // your string
-
String[] parts= s.split(",");
-
for (int i= 0; i < parts.length; i++)
-
System.out.println("parts["+i+"]= "+parts[i]);
-
kind regards,
Jos
ps. adding a bunch of exclamation marks won't help.
[quote=JosAH]First read this and then try this: -
String s= // your string
-
String[] parts= s.split(",");
-
for (int i= 0; i < parts.length; i++)
-
System.out.println("parts["+i+"]= "+parts[i]);
-
QUOTE]
hello JosAH
i think first u have to add this line!!! -
//after String s = "" //ur string.
-
s=s.substring(0,s.indexOf(":"));
-
because split() will work using " , " and will consider the xxxx:1234, as one part!
am i right?
thanks
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?
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.
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 ;-)
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |