techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Nov 20, 2012, 03:43 PM   #1
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Split String - Java

Hi all,

I've created a program to split a string which contains latitude coordinates.

Code:
 String[] temp;
        
        String delimiter = "°";
        
        temp = MetaData.latitude.split(delimiter);
 
        for (int i = 0; i < temp.length; i++) {
            System.out.println(temp[i]);
        }
For arguments sake, here is a latitude string: 52°97'0.6822"

The program above will only do up to 97. I was thinking of using a loop, but unsure how to go about doing it.

Any input would be helpful.

Cheers

Wozzer is offline  
Reply With Quote
Old Nov 20, 2012, 06:27 PM   #2
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

You could try using the regex or operator.
Code:
String[] temp = MetaData.latitude.split("°|\\'|\\"")
I'm not sure if I got the regex syntax correct. lol
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is offline  
Reply With Quote
The Following 2 Users Say Thank You to Kreij For This Useful Post:
Old Nov 20, 2012, 06:35 PM   #3
W1zzard
Benevolent Dictator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,873 (4.17/day)
Thanks: 184
Thanked 10,454 Times in 3,219 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard Send a message via Skype™ to W1zzard

System Specs

you definitely want to use a regular expression for this. to parse the whole thing, dont split
W1zzard is offline  
Reply With Quote
Old Nov 20, 2012, 09:57 PM   #4
Maelstrom
500 Posts
 
Maelstrom's Avatar
 
Join Date: Sep 2008
Location: VA/PA
Posts: 500 (0.29/day)
Thanks: 139
Thanked 164 Times in 121 Posts

System Specs

Quote:
Originally Posted by Kreij View Post
You could try using the regex or operator.
Code:
String[] temp = MetaData.latitude.split("°|\\'|\\"")
I'm not sure if I got the regex syntax correct. lol
What you wrote throws an error when compiling. Should be:
Code:
String[] temp = MetaData.latitude.split("°|\'|\"")
The regex stuff does work though (Thanks for showing that Kreij! Didn't know about that):

__________________

Made by PVTCaboose1337
Maelstrom is offline  
Reply With Quote
The Following User Says Thank You to Maelstrom For This Useful Post:
Old Nov 20, 2012, 10:09 PM   #5
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

Quote:
Originally Posted by Maelstrom View Post
What you wrote throws an error when compiling. Should be:
Code:
String[] temp = MetaData.latitude.split("°|\'|\"")
The regex stuff does work though (Thanks for showing that Kreij! Didn't know about that):

http://img.techpowerup.org/121120/javatest.png
Yeah, that why I said I wasn't sure about the syntax and if it needed to be double backslashed.
I'm also not sure what he plans on doing with the coordinates once they are split out.
He should put them in a float array if he will need to do calculation with them.
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is offline  
Reply With Quote
Old Nov 20, 2012, 10:30 PM   #6
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Quote:
Originally Posted by Kreij View Post
He should put them in a float array if he will need to do calculation with them.
The answer to my next question

I'm converting decimal degrees into degrees, minutes, seconds.

Thanks Kreij
Wozzer is offline  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
String problem with c++ game Aleksander Programming & Webmastering 42 Sep 26, 2011 06:08 PM
A Little String Help Needed dcf-joe Programming & Webmastering 4 Feb 10, 2010 04:39 AM
grep & hidden string alias' Viscarious Linux / BSD / Mac OS X 3 Sep 28, 2009 02:13 AM
Symantec corprate a/v scan string [I.R.A]_FBi General Software 7 Jul 25, 2007 04:59 PM


All times are GMT. The time now is 11:55 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts