Count the number of lines in all of my java files.
I have created a reasonable size project with about 20 classes, rather than going through each and counting the lines are their any programs maby integrated into forte or another ide which can do this?
Thanks
Actually, if you are looking for kloc statitics, it is more complicated. You would not want blank lines counted. You may also want to separate out the counts for comments vs. code. Also seprations between JavaDoc comments and commented-out code. There are free and commercial programs which do this, or you can write your own.
Similar Messages
-
Hi All,
I want to count the Number of lines that the user had entered in a multi-lined text box.
Because I want to restrict him up-to 6 lines.
How Can I don this.
Thanks in Advance,sql>select length('count no
of line
in the text')-length(replace('count no
of line
in the text',chr(10),'')) lines
from dual;
LINES
2
jeneesh -
How to count the number of lines dynamically,
In the below code am trying to read the lines which are selected using a check box, also am categorizing the contents depending on the follow up material.
after displaying one category contents am displaying a line
which also counts to a line in the internal table.
My question is how to count the number of lines(ULINE) displayed dynamically.
FORM GET_LINES .
DATA: LV_LINES TYPE I,
LV_TIMES TYPE I,
LV_TABIX TYPE SY-TABIX.
DESCRIBE TABLE IT_REC LINES LV_LINES.
DO LV_LINES TIMES.
LV_TIMES = SY-INDEX .
READ LINE LV_TIMES FIELD VALUE IT_REC-CHECK INTO GV_CHECK.
IF SY-SUBRC EQ 0 AND GV_CHECK IS NOT INITIAL.
LV_TABIX = LV_TIMES.
READ TABLE IT_REC INDEX LV_TABIX INTO GWA_UPDATE.
IF SY-SUBRC EQ 0.
APPEND GWA_UPDATE TO GT_UPDATE.
ENDIF.
ENDIF.
ENDDO.
ENDFORM. " GET_LINESIn the below code am trying to read the lines which are selected using a check box, also am categorizing the contents depending on the follow up material.
after displaying one category contents am displaying a line
which also counts to a line in the internal table.
My question is how to count the number of lines(ULINE) displayed dynamically.
FORM GET_LINES .
DATA: LV_LINES TYPE I,
LV_TIMES TYPE I,
LV_TABIX TYPE SY-TABIX.
DESCRIBE TABLE IT_REC LINES LV_LINES.
DO LV_LINES TIMES.
LV_TIMES = SY-INDEX .
READ LINE LV_TIMES FIELD VALUE IT_REC-CHECK INTO GV_CHECK.
IF SY-SUBRC EQ 0 AND GV_CHECK IS NOT INITIAL.
LV_TABIX = LV_TIMES.
READ TABLE IT_REC INDEX LV_TABIX INTO GWA_UPDATE.
IF SY-SUBRC EQ 0.
APPEND GWA_UPDATE TO GT_UPDATE.
ENDIF.
ENDIF.
ENDDO.
ENDFORM. " GET_LINES
The display function is:
FORM DISPLAY_DATA .
ULINE.
WRITE : /1 SY-VLINE, 'check',
10 SY-VLINE, 'Plant',
20 SY-VLINE, 'Material number',
50 SY-VLINE, 'Follow up material',
70 SY-VLINE, 'Safety stock',
100 SY-VLINE, 'Partc'.
ULINE.
LOOP AT IT_MARC.
MOVE: IT_MARC-WERKS TO IT_REC-WERKS,
IT_MARC-MATNR TO IT_REC-MATNR,
IT_MARC-NFMAT TO IT_REC-NFMAT,
IT_MARC-EISBE TO IT_REC-EISBE,
IT_MARC-PARTC TO IT_REC-PARTC .
APPEND IT_REC.
CLEAR IT_MARC.
ENDLOOP.
DATA: GV_TABIX TYPE SY-TABIX.
LOOP AT IT_REC.
GV_TABIX = SY-TABIX.
READ TABLE GT_TOTAL WITH KEY WERKS = IT_REC-WERKS
NFMAT = IT_REC-NFMAT.
IF SY-SUBRC EQ 0.
IT_REC-PARTC = GT_TOTAL-PARTC.
MODIFY IT_REC INDEX GV_TABIX TRANSPORTING PARTC.
ENDIF.
ENDLOOP.
LOOP AT IT_REC.
WRITE : /1 SY-VLINE, IT_REC-CHECK AS CHECKBOX,
10 SY-VLINE, IT_REC-WERKS,
20 SY-VLINE, IT_REC-MATNR,
50 SY-VLINE, IT_REC-NFMAT,
70 SY-VLINE, IT_REC-EISBE,
100 SY-VLINE, IT_REC-PARTC.
AT END OF NFMAT.
ULINE.
ENDAT.
ENDLOOP.
ULINE.
ENDFORM. " DISPLAY_DATA
Solved -
Count the number of lines in a txt file
I need to count the number of lines in a txt file, but I can't do it using readLine(). This is because the txt file is double spaced. readLine() returns null even if it is not the end of the file. thanks for the help
I need to count the number of lines in a txt file,
but I can't do it using readLine(). Then just compare each single byte or char to the newline (code 10).
This is because the txt file is double spaced. readLine() returns
null even if it is not the end of the file.Errm what? What do you mean by "double spaced"? Method readLine() should only return null if there's nothing more to read. -
Count the number of lines in each file in a directory
Hello,
I would like to count the number of lines for each file in my directory and subdirectories.
I wonder how can I count the lines of the specified files?
Here is the program which is listed the files in the specified directory:
String path = "C:/User/Studies/Pracices/src/Pract1";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles.isFile())
files = listOfFiles[i].getName();
System.out.println(files);Ok so one more question.
Actually my path is pointing to one Directory and like here I can just read from one file that the name of the file should be specified in the path is it possible to help me in that part?
File f = new File("C:/User/Studies/Practices/src/Pract1/");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String str = br.readLine();
LineNumberReader ln = new LineNumberReader(br);
int count = 0;
while (ln.readLine()!=null)
count++;
System.out.println("no. of lines in the file = " + count); -
Java Program+To count the number of lines in a method excluding comments???
Hi friends
can u plz help me out, the java program is counting the number of lines in a method excluding comments.
The first thing is how to identify a method, then there can be an inner method inside the parent method,
Please friends its urgent
Bye
SandyThere's no such thing as an inner method in Java. You can either write the code yourself to parse Java source, or maybe something like ANTLR can do it.
-
Counting the number of lines for each procedure in a package
Hi,
I would like to write a query on USER_SOURCE that can display the number of code lines for each procedure/function in a package.
Is it possible to write such a query? Maybe by using analytical functions?
for example in the following example i would like to count the lines between "PROCEDURE proc1 IS" and "END proc1;" and between "PROCEDURE proc2 IS" and "END proc2;"
SQL> select text from user_source where name='PKG_TEST' and type='PACKAGE BODY';
TEXT
PACKAGE BODY PKG_TEST IS
PROCEDURE proc1 IS
BEGIN
update t1 set EDITION_NAME = 'AAAAAAA';
commit;
END proc1;
PROCEDURE proc2 IS
BEGIN
update t1 set EDITION_NAME = 'AAAAAAA';
commit;
END proc2;
END PKG_TEST;thanks for helpingonedbguru wrote:
Hopefully some idiot manager isn't trying to use this sort of thing to base their decisions on developer productivity. If so, they ARE idiots. Number of code lines NEVER, EVER, EVER!!! translates into an efficient application. If I were paid by the line, my code would look like:
select
1
from
dual
Based on the idiocy of this method of determining "performance" I would get paid $5.00 at $1.00/line. And trust me, I saw this back in the 80's and 90's and saw similar idiotic code and had to clean up the mess. Most of it wasn't efficient code to start with let alone the number of lines generated.Or the other extreme, when the PHB firmly believed that execution efficiency was gained by reducing the number of lines of code. So instead of nicely formatted, easy to read code:
*GET NEXT ORDER NUMBER
EXEC SQL
SELECT (MAX(ORDER_NUM) + 1)
INTO :NEXT-NUM:IND-NULL
FROM PART_ORDER
END-EXEC.
IF IND-NULL < 0
MOVE 1 TO NEXT-NUM.
EXEC SQL
INSERT
INTO PART_ORDER
(ORDER_NUM,
ORIGIN_LOC,
ORDER_TYPE,
ORDER_STAT,
CREAT_TIME)
VALUES (:NEXT-NUM,
:LOC, 'R', 'O',
CURRENT TIMESTAMP)
END-EXEC.
MOVE NEXT-NUM TO MASK0.
PERFORM HEADER-PROC THRU HEADER-EXIT.
CREATE-ORDER-EXIT. EXIT. You got this:
*GET NEXT ORDER NUMBER
EXEC SQL SELECT (MAX(ORDER_NUM) + 1) INTO :NEXT-NUM:IND-NULL FROM
PART_ORDER END-EXEC. IF IND-NULL < 0 MOVE 1 TO NEXT-NUM. EXEC SQL INSERT
INTO PART_ORDER (ORDER_NUM, ORIGIN_LOC, ORDER_TYPE, ORDER_STAT,
CREAT_TIME) VALUES (:NEXT-NUM, :LOC, 'R', 'O', CURRENT TIMESTAMP)
END-EXEC. MOVE NEXT-NUM TO MASK0. PERFORM HEADER-PROC THRU HEADER-EXIT.
CREATE-ORDER-EXIT. EXIT. Oh, wait! See the same thing all the time in this forum ... not because someone thinks fewer lines = faster code, but simply because people are sloppy.
INSERT INTO PART_ORDER(ORDER_NUM,ORIGIN_LOC,ORDER_TYPE,ORDER_STAT,CREAT_TIME) VALUES (:NEXT-NUM,:LOC, 'R', 'O',CURRENT TIMESTAMP) ; -
Count the number of Lines with in a method
I am trying to write a program that will report back the number of methods/types/names and proxies as well as the number of lines of code in each method... I can not figure out how to count each methods line of code separately thanks. each method is commented by
/* PROXY proxyname type */
/* METHOD method name*/
public class Assignment3
private static BufferedReader userInput = new BufferedReader (new InputStreamReader (System.in));
* @param args
* @throws IOException
* @param args
* @throws IOException
public static void main(String[] args) throws IOException
System.out.print("Enter the .java file name: ");
String input = userInput.readLine();
while (!input.equalsIgnoreCase("stop"))
System.out.println("Total Number of Lines: " + LOC(input) + "\n" + Method(input) + "\n" + Type(input));
System.out.print("\nEnter file name to search again or \"stop\" to terminate the program: ");
input = userInput.readLine();
public static int LOC(String inputFile) throws IOException, FileNotFoundException
int numLines = 0;
try
FileReader FileIn = new FileReader(inputFile);
Scanner scanLines = new Scanner (FileIn);
String line;
while (scanLines.hasNext())
line = scanLines.nextLine();
if (line.startsWith("/*"))
numLines--;
else if(!line.equals(" "))
numLines++;
FileIn.close();
catch(IOException IOE)
System.out.println("\nFile Not Found!");
return numLines;
public static int MethodLOC(String inputFile) throws IOException, FileNotFoundException
File FileIn = new File(inputFile);
Scanner scanLines = new Scanner (FileIn);
String line = null;
int methodLOC = 0;
while(scanLines.hasNext())
line = scanLines.nextLine();
if(!line.contains("/*"))
StringTokenizer st = new StringTokenizer(line, "\n");
methodLOC = st.countTokens();
return methodLOC;
public static String Method(String inputFile) throws IOException, FileNotFoundException
String line = null;
String name = null;
String info = null;
File FileIn = new File(inputFile);
Scanner scanLines = new Scanner (FileIn);
while(scanLines.hasNext())
line = scanLines.nextLine();
if(line.contains("METHOD"))
StringTokenizer st = new StringTokenizer(line, " ");
String proxy = st.nextToken();
String method = st.nextToken();
name = st.nextToken();
info = "Name of Method: " + name;
return info;
public static String Type(String inputFile) throws IOException, FileNotFoundException
String line = null;
String name = null;
String info = null;
String count = null;
File FileIn = new File(inputFile);
Scanner scanLines = new Scanner (FileIn);
while(scanLines.hasNext())
if(line.contains("PROXY"))
StringTokenizer st = new StringTokenizer(line, " ");
String proxy = st.nextToken();
String method = st.nextToken();
name = st.nextToken();
String type = st.nextToken();
info = "Name of Proxy: " + name + "\n" + "Type of Proxy: " + type;
count = info;
return count;
}Iterate through the lines and count the opening and closing curly braces. Whenever you see an opening one, increase the counter, when you see a closing one, decrease the counter. When the counter hits 0 again, you reached the end of the method.
I assume you know how to count lines while moving through a text line by line. -
Count the number of occurences of a pattern in some files
Hi,
I am trying to extract some patterns in files using regex. I can easily extract the patterns using my program. I also wanted to count the number of occurences of the pattern in the files. For that I have written this code:
int count=0;
while (m.find())
System.out.println("Found Patterns: "+m.group());
count++;
System.out.println(count); //giving error saying identifier expectedUnfortunately I am getting an error saying identifier expected at the count line. What to do?
ThanksCheapside-Poultry wrote:
Move the } down one line so the count is in scope.No, it looks like he just forgot the opening { with the while. -
Have EEM count the number of Lines
In *nix this is as simple as "wc -l" but unfortunately I can't seem to find a simple solution. For the purposes of this thread here is my test script...
event manager applet TEST authorization bypass
event syslog pattern "TRIGGER"
action 1.0 cli command "enable"
action 2.0 cli command "conf t"
action 3.0 cli command "show log"
action 4.0 cli command "COUNT NUMBER OF LINES FROM SHOW LOG -- $_cli_result"
Can someone let me know what action 4.0 would be in order to complete this task?
Thanks!Actually, that parially worked. Perhaps you can help me troubleshoot the results I am getting.
Here is my test script:
edge2821a#show run | sec eventevent manager applet TEST authorization bypass event none action 1.0 cli command "enable" action 2.0 cli command "conf t" action 3.0 cli command "show ip nat trans" action 4.0 set LINES "0" action 4.1 foreach line "$_cli_result" "\n" action 4.2 increment LINES action 4.3 end action 4.4 puts "Number of NAT Translations: $LINES"
Here is my actual NAT translation table:
edge2821a#show ip nat translationsPro Inside global Inside local Outside local Outside globaludp 72.68.68.238:123 10.0.10.200:123 66.27.60.10:123 66.27.60.10:123tcp 72.68.68.238:4030 10.0.20.100:4030 --- ---tcp 72.68.68.238:4031 10.0.20.100:4031 --- ---tcp 72.68.68.238:23 10.0.20.105:22 --- ---tcp 72.68.68.238:80 10.0.20.105:80 199.248.199.110:59691 199.248.199.110:59691tcp 72.68.68.238:80 10.0.20.105:80 --- ---tcp 72.68.68.238:9090 10.0.20.201:8080 --- ---tcp 72.68.68.238:443 10.0.20.225:80 --- ---tcp 72.68.68.238:9022 10.0.21.230:22 173.70.201.69:49353 173.70.201.69:49353tcp 72.68.68.238:9022 10.0.21.230:22 --- ---udp 72.68.68.238:50817 10.0.21.231:50817 63.142.161.5:3997 63.142.161.5:3997udp 72.68.68.238:55703 10.0.21.231:55703 63.142.161.5:1194 63.142.161.5:1194udp 72.68.68.238:49917 10.0.30.30:49917 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:50011 10.0.30.30:50011 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:51973 10.0.30.30:51973 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:56512 10.0.30.30:56512 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:56639 10.0.30.30:56639 71.250.0.12:53 71.250.0.12:53tcp 72.68.68.238:57373 10.0.30.30:57373 64.12.24.171:443 64.12.24.171:443tcp 72.68.68.238:57404 10.0.30.30:57404 173.194.73.125:5222 173.194.73.125:5222Pro Inside global Inside local Outside local Outside globaltcp 72.68.68.238:57412 10.0.30.30:57412 173.194.68.109:465 173.194.68.109:465tcp 72.68.68.238:57413 10.0.30.30:57413 173.194.68.109:587 173.194.68.109:587tcp 72.68.68.238:57414 10.0.30.30:57414 173.194.68.109:465 173.194.68.109:465udp 72.68.68.238:57572 10.0.30.30:57572 71.250.0.12:53 71.250.0.12:53tcp 72.68.68.238:60348 10.0.30.30:60348 173.194.76.108:993 173.194.76.108:993udp 72.68.68.238:60413 10.0.30.30:60413 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:61461 10.0.30.30:61461 71.250.0.12:53 71.250.0.12:53tcp 72.68.68.238:61632 10.0.30.30:61632 17.149.36.76:5223 17.149.36.76:5223udp 72.68.68.238:62019 10.0.30.30:62019 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:63756 10.0.30.30:63756 71.250.0.12:53 71.250.0.12:53udp 72.68.68.238:65134 10.0.30.30:65134 71.250.0.12:53 71.250.0.12:53tcp 72.68.68.238:65188 10.0.30.30:65188 173.194.68.109:993 173.194.68.109:993tcp 72.68.68.238:65274 10.0.30.30:65274 173.194.74.108:993 173.194.74.108:993tcp 72.68.68.238:65310 10.0.30.30:65310 173.194.76.108:993 173.194.76.108:993tcp 72.68.68.238:65311 10.0.30.30:65311 173.194.68.108:993 173.194.68.108:993tcp 72.68.68.238:65312 10.0.30.30:65312 173.194.68.108:993 173.194.68.108:993tcp 72.68.68.238:65374 10.0.30.30:65374 173.194.76.108:993 173.194.76.108:993tcp 72.68.68.238:65429 10.0.30.30:65429 173.194.74.109:993 173.194.74.109:993tcp 72.68.68.238:65466 10.0.30.30:65466 74.125.226.195:80 74.125.226.195:80tcp 72.68.68.238:65467 10.0.30.30:65467 74.125.226.200:80 74.125.226.200:80tcp 72.68.68.238:65469 10.0.30.30:65469 173.194.43.7:443 173.194.43.7:443tcp 72.68.68.238:65470 10.0.30.30:65470 173.194.43.7:443 173.194.43.7:443tcp 72.68.68.238:65471 10.0.30.30:65471 173.194.43.7:443 173.194.43.7:443Pro Inside global Inside local Outside local Outside globaltcp 72.68.68.238:65472 10.0.30.30:65472 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65473 10.0.30.30:65473 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65474 10.0.30.30:65474 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65475 10.0.30.30:65475 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65476 10.0.30.30:65476 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65477 10.0.30.30:65477 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65478 10.0.30.30:65478 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65479 10.0.30.30:65479 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65480 10.0.30.30:65480 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65481 10.0.30.30:65481 173.194.75.99:443 173.194.75.99:443tcp 72.68.68.238:65482 10.0.30.30:65482 192.168.1.1:2555 192.168.1.1:2555tcp 72.68.68.238:65484 10.0.30.30:65484 206.46.232.12:465 206.46.232.12:465tcp 72.68.68.238:65485 10.0.30.30:65485 173.194.68.109:465 173.194.68.109:465tcp 72.68.68.238:65486 10.0.30.30:65486 173.194.68.109:465 173.194.68.109:465tcp 72.68.68.238:65487 10.0.30.30:65487 173.194.68.109:587 173.194.68.109:587tcp 72.68.68.238:52115 10.0.30.60:52115 204.8.241.230:443 204.8.241.230:443tcp 72.68.68.238:52523 10.0.30.60:52523 204.8.241.230:443 204.8.241.230:443tcp 72.68.68.238:52524 10.0.30.60:52524 204.8.241.230:443 204.8.241.230:443tcp 72.68.68.238:52525 10.0.30.60:52525 204.8.241.230:443 204.8.241.230:443tcp 72.68.68.238:52571 10.0.30.60:52571 17.172.232.217:5223 17.172.232.217:5223tcp 72.68.68.238:52861 10.0.30.60:52861 173.194.74.108:993 173.194.74.108:993tcp 72.68.68.238:53667 10.0.30.60:53667 204.8.241.230:443 204.8.241.230:443Pro Inside global Inside local Outside local Outside globaltcp 72.68.68.238:53668 10.0.30.60:53668 173.194.68.109:993 173.194.68.109:993tcp 72.68.68.238:50519 10.0.30.62:50519 69.171.230.22:443 69.171.230.22:443tcp 72.68.68.238:50597 10.0.30.62:50597 17.149.36.120:443 17.149.36.120:443tcp 72.68.68.238:50889 10.0.30.62:50889 173.252.103.48:443 173.252.103.48:443tcp 72.68.68.238:51959 10.0.30.62:51959 23.67.251.64:80 23.67.251.64:80tcp 72.68.68.238:52085 10.0.30.62:52085 69.171.233.33:443 69.171.233.33:443tcp 72.68.68.238:52091 10.0.30.62:52091 17.149.36.162:443 17.149.36.162:443tcp 72.68.68.238:52216 10.0.30.62:52216 17.172.233.111:443 17.172.233.111:443tcp 72.68.68.238:53102 10.0.30.206:53102 184.51.206.137:80 184.51.206.137:80tcp 72.68.68.238:52958 10.0.30.233:52958 173.194.68.108:993 173.194.68.108:993tcp 72.68.68.238:52959 10.0.30.233:52959 173.194.68.109:993 173.194.68.109:993tcp 72.68.68.238:52961 10.0.30.233:52961 173.194.68.108:993 173.194.68.108:993tcp 72.68.68.238:52962 10.0.30.233:52962 173.194.68.108:993 173.194.68.108:993tcp 72.68.68.238:59069 10.0.30.233:59069 17.158.10.36:443 17.158.10.36:443tcp 72.68.68.238:59070 10.0.30.233:59070 17.158.10.36:443 17.158.10.36:443tcp 72.68.68.238:59072 10.0.30.233:59072 74.125.226.233:443 74.125.226.233:443tcp 72.68.68.238:65140 10.0.30.233:65140 173.194.73.125:5222 173.194.73.125:5222tcp 72.68.68.238:53041 10.0.30.234:53041 173.194.68.108:993 173.194.68.108:993tcp 72.68.68.238:53250 10.0.30.234:53250 173.194.74.108:993 173.194.74.108:993tcp 72.68.68.238:53520 10.0.30.234:53520 17.172.232.158:443 17.172.232.158:443tcp 72.68.68.238:54172 10.0.30.235:54172 17.149.36.165:5223 17.149.36.165:5223tcp 72.68.68.238:54173 10.0.30.235:54173 17.172.238.204:443 17.172.238.204:443Pro Inside global Inside local Outside local Outside globaltcp 72.68.68.238:55523 10.0.30.235:55523 173.194.76.108:993 173.194.76.108:993
Here is the output of my EEM script:
edge2821a#event manager run TESTNumber of NAT Translations: 4
The value of $LINES shoudl have been 92, not 4. Can you help me to identify the problem?
Thanks! -
Findind out the number of lines within a string - using buffered reader
Hi All,
Want to know the number of lines within a string..Sample code is there for reference..could u help me out how to have the number of lines in a string without java comments (i.e string within /**------*/ and // should be eliminated)
public class ReadLines {
public static void main(String[] args) throws Exception{
ReadLines rl = new ReadLines();
rl.readLines();
void readLines() throws Exception{
String str = "/** This is a test message\n"+
"* for testing\n"+
"*/\n"+
"import java.io.*\n"+
"// this is again comment\n"+
"public class ReadLines {\n"+
BufferedReader reader = new BufferedReader(new StringReader(str));
String line = "";
int count = 0;
while ((line = reader.readLine())!= null )
//line = reader.readLine();
count++;
System.out.println(count);
}Thanks
MKHi
What you need to do is parse the file in such a way that you read /*, */ and // as tokens. By that I mean rather than read a line at a time (although I'm sure you could), read it character by character. So every time you reach a new line character then increment the counter. But there are two casaes when you don increment the counter they are:
If you encounter a / followed by * then keep reading but if you encounter a newline character then DONT increment the counter ONLY continue counting when you read a * followed by a / (as this is the end of the comment)
If you encounter / followed by another / then do not count that particular line and go to the next line and continue counting from there.
Where I've written 'continue counting' this is subject to the lines that follow not conforming to the above two cases.
I hope this helps. -
How can i read the number of lines written - in spreadshee​t array?
hello NI,
I am writing file as spreadsheet format continuously, contains date, time, chanel1, channel 2, channel 3..... etc.
i just want to know how many lines has been written after file write....
Regards,
Balaji DPYou count the number of line termination char. Se example
Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Attachments:
sample.PNG 25 KB -
How to Count the number of TAB chars value '0A' in a line?
I have a requirement to count the number of TABs in a text file that I am processing (they must equal 75) to ensure that all the fields have been submitted on the file I am reading?
How do I identify the TABs in a line?
I have this so far:
CONCATENATE gv_unix_file gv_lstfiles-name INTO gv_unix_file.
OPEN DATASET gv_unix_file for INPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc <> 0 .
message e000(zz) with 'Cannot access in_uk files'.
ENDIF.
CONCATENATE gv_unix_file_arc gv_lstfiles-name INTO gv_unix_file_arc.
OPEN DATASET gv_unix_file_arc FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc <> 0 .
message e000(zz) with 'Cannot access in_uk files'.
ENDIF.
DO.
READ DATASET gv_unix_file into lv_str.
IF sy-subrc <> 0.
exit. "exit do loop, file is done.
else.
TRANSFER lv_str to gv_unix_file_arc.
ENDIF.
ENDDO.Here is a sample code:
DATA: lv_string TYPE string,
lv_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
lv_i TYPE i.
DATA: result_tab TYPE match_result_tab.
DO 3 TIMES.
CONCATENATE 'A' lv_string INTO lv_string SEPARATED BY lv_tab.
ENDDO.
" this is how you need to find how many tabs are in your transfer work area...
FIND ALL OCCURRENCES OF lv_tab IN lv_string RESULTS result_tab.
DESCRIBE TABLE result_tab LINES lv_i.
WRITE:'No. of tabs found:', lv_i. -
Count the number of extracted lines
Access vekp with vekp-objkey = mkpf-xblnr and vekp-vpobj = '03' and vekp-uevel = blank.
Get field vekp-venum.
Access again vekp with vekp-vpobjkey = mkpf-xblnr and vekp-uevel = vekp-venum.
Count the number of extracted lines.Hi,
First u should start writing the code on ur own:
here's some sketch:
tables: vekp, mkpf.
data: begin of itab_vekp occurs 0,
venum like vekp-venum,
end of itab_vekp.
data: begin of itab_mkpf occurs 0,
xblnr like mkpf-xblnr,
end of itab_mkpf.
data: count type i.
select-options: s_xblnr for mkpf-xblnr.
select xblnr from mkpf into table itab_mkpf where xblnr in s_xblnr.
select venum from vekp
into table itab_vekp
* for all entries in itab_mkpf
where vpobjkey = itab_mkpf-xblnr
and vpobj = '03'
and uevel = ' '.
if sy-subrc eq 0.
count = sy-dbcnt.
endif.
Edited by: Mahesh Reddy on Mar 4, 2009 7:07 AM -
Help with how to count the number of tokens from the first line
Hi
I want to count the number of tokens from the first line of text, from my incoming file and print it out.
For example i have 12 tokens in the first line, so i want it to print out the number 12
my code is below
thanks
import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.StringTokenizer.*;
import java.sql.*;
public class Data {
public static void main(String[] args) {
String token = null;
String currentToken = "";
Hashtable hh = new Hashtable();
try {
Vector v2 = new Vector(100);
Vector v = new Vector(100);
FileReader file = new FileReader("words.txt");
BufferedReader buff = new BufferedReader(file);
String line = buff.readLine();
StringTokenizer s = null;
boolean eof = false;
while (!eof){
s = new StringTokenizer(line.trim(),",",true);
boolean lastToken = true;
while (s.hasMoreTokens()) {
token = s.nextToken();
if (lastToken){
if (token.equals(",")) {
v.add("");
lastToken = false;
if (! token.equals(",")) {
v.add(token);
else { if (currentToken.equals(",")) {
v.add("");
currentToken = token;
if (token.equals(",")) {
v.add("");
line = buff.readLine();
if (line == null){
eof = true;}
buff.close();
}catch (FileNotFoundException fe) {
System.out.println("Error - - " + fe.toString());
}catch (NumberFormatException ne) {
System.out.println("Error - - " + ne.toString());
} catch (IOException e) {
System.out.println("Error - - " + e.toString());
} 2.I can print out the amount of tokens from each line,
But i only want the first line to be counted, And i
also do not want the delimeters to be counted.
could you please give me some ideas?
Thanks
try
BufferedReader br = new BufferedReader(new FileReader("item.kr"));
while((str=br.readLine())!= null)
itemslist.add(str);
catch(IOException ioe)
System.out.println("Exception Occurred!!!");
}This snippet gets one Line from the item.kr file.
Then i would count (By useing a diffrent String Tokenizer) to count only this line!!!
Maybe you are looking for
-
Error while posting sec.HighEd cess (1%) in J1iin.
we got following error while posting excise invoice J1IIN. all excise rates/values (10%,2%,1%) are coming properly in J1iin. if we remove excise duty 1% sec-high-ed-cess, than excise accounting entries posted properly in J1iin. but excise duty 1% (se
-
Help me find file edit view window and help in photoshop elements 9
I bought a new computer and my photoshop opens but the line with file exit find view and help does nor appear. How can I download my pictures now?
-
Hallo, zum Vertonen meiner Super 8 Filme benutze ich Adobe Audion 2.0 seit Jahren mit dem portabelen USB-Audio-Interface EMI 2/6 von emagic mit großem Erfolg. Nun steht der Wechsel von Windows XP zu Windows 8. Gerne würde ich Adobe Audition auch mit
-
OdiIinvokeWebService - SOAP - HTTP header
Using OdiIinvokeWebService and HTTPS protocol, can an HTTP header be passed with the SOAP request? Thank you
-
If I bought a late 2012 mac mini, should I get a copy of the Mountain Lion OS as well?
I recently bought a mac mini within the last 2 months. Love the computer. But what I want to know is, shouldn;t I get a divital copy of the OS? I mean, if you buy a computer, you typically get the install discs fior the OS. Shouldn;t I be entitlted t