/    Sign up×
Community /Pin to ProfileBookmark

splitting a string

I have a string that represents a phone number (1234567890). I am trying to split out the area code and the phone number so I can format it like 123-456-7890. Below is my code, but it never gets past where I am printing out the phone1, and the phone1 is printing blank. Could someone help me with formatting the phone number?

[code]
phone = phone.replaceAll(“[^0-9]”,””);
String areaCode = phone.substring(0,3);
System.out.println(“area code: “+areaCode);
String phone1 = phone.substring(3,3);
System.out.println(“phone1: “+phone1);
String phone2 = phone.substring(6,4);
System.out.println(“phone2: “+phone2);
[/code]

Thanks

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@jrthor2authorJan 25.2008 — I got this working.
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...