Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 2nd, 2012, 08:24 PM
vickyv200 vickyv200 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 18 vickyv200 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 17 m 32 sec
Reputation Power: 0
String questions.

What I'm trying to do is read in from a file, and then every time a specific character appears in the file I want to insert a variable directly directly after it and then output the same thing I read in except with the variable inserted in.

So if the line was
Hey how's ( it going?
I would want it to read
Hey how's (variable it going?

How would I do this?

Reply With Quote
  #2  
Old November 4th, 2012, 01:26 AM
vickyv200 vickyv200 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 18 vickyv200 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 17 m 32 sec
Reputation Power: 0
Well I managed to think of something myself. But I still need help.
The problem with this is every line that has a "{" in it is output twice one without the counter added and one with. I'd like someone to point out how I can make it work. Here is the section of my original code.

Code:
while(in.hasNextLine()) {
StringBuffer line = new StringBuffer(in.nextLine());
out.println(line);
for(int i = 0; i <line.length(); i++) 
{
if(line.charAt(i)=='{')
{
counter++;
line.insert(i+1, counter);
out.println(line);
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > String questions.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap