Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-09-2008, 12:22 PM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Default [SOLVED] How to achieve this?
i am having data like this:Input say it as a.txt

S.No Description Qty. Units Rate (Rs.) Value (Rs.)
1 Aviation Lamp 1 Nos 3700 3,700
2 Lighting Arrester 1 Nos 1600 1,600
3 Aviataion Lamp Cable 31 Rmt 270 8,370

Gross Total 13,670
The above Total include Services Tax Amount of Rs 536
Total Invoice Value 13,670

i would like to get this data in the form of:Output should be

S.No 1
Description Aviation Lamp
Qty. 1
Units Nos
Rate (Rs.) 3700
Value (Rs.) 3700

S.No 2
Description Lighting Arrester
Qty.1
Units Nos
Rate (Rs.) 1600
Value (Rs.) 1600

S.No 3
Description Aviataion Lamp Cable
Qty.31
Units Nos Rmt
Rate (Rs.) 270
Value (Rs.) 8,370

Gross Total 13,670
Tax Amount of Rs 536
Total Invoice Value 13,670

--------------------------------

I tried with Buffered Reader, String Buffer used some regex code.but i am unable to get this..can any body help me in this..one more thing i want s to generate this should work dynamically...If we give any input .txt file the corresponding text should be convert into that format
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-09-2008, 03:07 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 254
Rep Power: 2
sanjeevtarar is on a distinguished road
Default
Is your input file format is fix like you have given....

and you want output as a .txt file.....


__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-09-2008, 03:07 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 537
Rep Power: 2
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Default
Given the contents of a.txt...

You should get some patterns there.

If the example you've given is like the quote below,

Quote:
S.No Description Qty. Units Rate (Rs.) Value(Rs.)
1 Aviation_Lamp 1 Nos 3700 3,700
2 Lighting_Arrester 1 Nos 1600 1,600
3 Aviataion_Lamp_Cable 31 Rmt 270 8,370
You can use Scanner class for this.

Code:
while(scannerObject.hasNext()){
       s.no = scannerObject.next();
       description = scannerObject.next();
       qty = scannerObject.next();
       unit = scannerObject.next();
       rate = scannerObject.next();
       value = scannerObject.next();
       print those values....
}
Try to have some experiments from it....
(Printing on console may be a good tests)

After that, read the Formatter class....
You can format it like the format you've post...

Code:
Formatter.format("%s\n", String);
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa; 05-09-2008 at 03:12 PM. Reason: Additional.....
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-12-2008, 11:41 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Lightbulb
thnaks
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-12-2008, 11:59 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Default
Quote:
public class TabData2 {

static String Sno,Qty,Description,Unit,Rate,Value;
public static void main(String args[]) throws FileNotFoundException{
File file = new File("D:\\bharath\\CSV\\tab2.txt");
StringBuilder sb = new StringBuilder();
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
// String line = scanner.nextLine();
// while(scanner.hasNext()){
Sno = scanner.next();
Description = scanner.next();
Qty = scanner.next();
Unit = scanner.next();
Rate = scanner.next();
Value = scanner.next();
Formatter fmt=new Formatter();
fmt.format("%s\n",Sno);
fmt.format("%s\n",Description);
fmt.format("%s\n",Qty);
fmt.format("%s\n",Rate);
fmt.format("%s\n",Value);


System.out.println(Sno);
System.out.println(Description);
System.out.println(Qty);
System.out.println(Rate);
System.out.println(Value);

}

}
}
i AM GETING ERRORS:My Output is:

sno
Description
Qty.
Rate
(Rs.)
Value
(Rs.)
1
Lamp
1
Nos
3700
3,700
Lighting
Arrester
1
Nos
1600
3
Aviataion
Lamp
Cable
31
270
8,370
Gross
Total
13,670
above
Total
include
Services
Tax
of
Rs
536
Total
Invoice
I
13,670
Now
Claimed
100%
Invoice
Value
13,670
(Rupees
Thirteen
Six
Hundred
and
Seventy
only)
Description
Qty.
Rate
(Rs.)
Value
1
Lamp
1
Nos
3700
Lighting
Arrester
1
Nos
1600
Aviataion
Lamp
Cable
31
270
Gross
Total
13,670
above
Total
Services
Tax
of
Rs
536
Invoice
I
13,670
Now
Claimed
Invoice
Value
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1347)
at TabData2.main(TabData2.java:31)



any one correct this..please..thnx...My desired output is :

S.No 1
Description Aviation Lamp
Qty. 1
Units Nos
Rate (Rs.) 3700
Value (Rs.) 3700

S.No 2
Description Lighting Arrester
Qty.1
Units Nos
Rate (Rs.) 1600
Value (Rs.) 1600

S.No 3
Description Aviataion Lamp Cable
Qty.31
Units Nos Rmt
Rate (Rs.) 270
Value (Rs.) 8,370

Gross Total 13,670
Tax Amount of Rs 536
Total Invoice Value 13,670
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-12-2008, 12:09 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Did you debug and try to understand what happened there? It's not difficult to get an idea pal.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-12-2008, 12:15 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
In simple word, in you file has 47 elements. Each time you read you read bundle of 6 elements. So what happened is, in last read you have only 5 elements. No 6th element.

Simply you get an exception.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-12-2008, 12:21 PM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Default
yeah...but i am not getting the output in the desired manner..???
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-12-2008, 12:22 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
What you mean there? I'm not clear. You just need element by element to display?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-12-2008, 12:28 PM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Default
As i told you in my posts my output should be in :

S.No 1
Description Aviation Lamp
Qty. 1
Units Nos
Rate (Rs.) 3700
Value (Rs.) 3700 format..
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-12-2008, 12:33 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Read a line, separate tokens and manipulate the required strings. I think it's the easiest way.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-12-2008, 01:07 PM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Default
thts ok..but if i want my O.P in the desired format...
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-13-2008, 02:42 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default
The number of characters are different. I think a simplier approach is to add a Delimeter. Then Cut the substring before the Delimeter. You can also check if there is a missing part in the line by counting the delimeters. Here is my suggestion.

S.No Description Qty. Units Rate (Rs.) Value (Rs.)
1$Aviation Lamp$1$Nos$3700$3,700$
2$Lighting Arrester$1$Nos$1600$1,600$
3$Aviataion Lamp Cable$31$Rmt$270$8,370$

Gross Total $13,670$
The above Total include Services Tax Amount of Rs $536$
Total Invoice Value $13,670$

thats how should it look. You can change the '$' sign if you like.
Then, extract all the content of the file into a single String.
Then, get all the Lines and save it into a variable.

Here is how i extracted the Number of Lines and lines in a Single String.
Code:
String LineFeed=null,line=null,Output=null; int ctr=0;
BufferedReader in = new BufferedReader(new FileReader("A.txt"));
                while ((line = in.readLine()) != null) {

                    LineFeed  += line;
                    ctr++;
                  }   LineFeed = LineFeed.substring(4);
Here is where i segregate the desired output i want
Code:
int ptr = ctr-4; String LineFeed2 = LineFeed;
for (i=1; i<ptr;i++){
       try{
        Output += "S.No " + LineFeed2.substring(0,LineFeed2.IndexOf("$")+"\n";
        LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
        Output += "Description " 
                   + LineFeed2.substring(0,LineFeed2.IndexOf("$")+"\n";
        LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
        Output += "Qty. " + LineFeed2.substring(0,LineFeed2.IndexOf("$")+"\n";
        LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
        Output += "Units " + LineFeed2.substring(0,LineFeed2.IndexOf("$")+"\n";
        LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
        Output += "Rate (Rs.) " 
                   + LineFeed2.substring(0,LineFeed2.IndexOf("$")+"\n";
        LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
        Output += "Value (Rs.) " 
                  + LineFeed2.substring(0,LineFeed2.IndexOf("$")+"\n"+"\n";
        LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
        } catch (Exception A){
        System.out.println("Error in Line Number: " + ptr+1);}
} LineFeed2 = LineFeed2.substring(4); //removing the null =)

//Adding the Last Line
LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
Output += "Gross Total " + LineFeed2.substring(0,LineFeed2.IndexOf("$");
LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
Output += "Tax Amount of Rs " 
          + LineFeed2.substring(0,LineFeed2.IndexOf("$");
LineFeed2 = LineFeed2.substring(IndexOf("$")+1);
Output += "Total Invoice Value " 
          + LineFeed2.substring(0,LineFeed2.IndexOf("$");
LineFeed2 = LineFeed2.substring(IndexOf("$")+1);

//Here is the output you Desire
System.out.println(Output);
I Hope that helps. God BLess in your Code

Last edited by Eku; 05-13-2008 at 02:46 AM.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-13-2008, 07:31 AM
jazz2k8's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 138
Rep Power: 0
jazz2k8 is on a distinguished road
Default
thanks for your advice...nice trick buddy.....
__________________
visit :
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-13-2008, 08:42 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default
No Problem . . . =)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Step-by-Step Tutorial: Achieve RAD with Seam+Eclipse+Tomcat Techieexchange JavaServer Faces 0 11-13-2007 07:13 PM


All times are GMT +2. The time now is 11:20 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org