Android Question Clear all comments codes

SMOOTSARA

Active Member
Licensed User
Longtime User
Hello friends
I want to clean the application code.
The number of lines of the B4A is more than 3000 lines, which is a lot of comments
Is there a quick way to identify commented lines? Until I clear them quickly
If this is not possible in the B4A , this could be a good suggestion for future releases.
Good luck
 

johndb

Active Member
Licensed User
Longtime User
I agree with @LucaMs, why delete your comments?
If you insist on deleting your comments then I would recommend that you write a small B4J program to open the .bas file and remove all lines starting with "'".
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User
I agree with @LucaMs, why delete your comments?
If you insist on deleting your comments then I would recommend that you write a small B4J program to open the .bas file and remove all lines starting with "'".
Hi dear friend
Is it possible to write this program?
I need to clear comments to provide the product to the customer
 
Upvote 0

johndb

Active Member
Licensed User
Longtime User
Hi dear friend
Is it possible to write this program?
I need to clear comments to provide the product to the customer
It is possible to write the program. It uses the same Basic syntax as B4A or any of the other B4X products. That's the wonderful thing about this RAD system.
If you are asking us to write the code for you then unfortunately my time is limited at the present time. Sorry.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I need to clear comments to provide the product to the customer
The source code?

Intendevo chiederti se devi cedere al tuo cliente il codice sorgente, non di inviarlo a me

If you sell your source code, I think that your customer will need the comments.
If you sell only the apk, you don't need to remove them.

Anyway, as @johndb wrote, it is simple to develop a small tool to remove COMMENT LINES (lines with commands and comments are more difficult to handle, of course).
Just a multi file selector, a button, CREATE BACKUPS, read all lines in a List, remove those that start with "'" from the list, save the list.
 
Last edited:
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User

Use a grep tool like grepWin to remove the comments.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Is there a quick way to identify commented lines?

This is a pretty good example of when it's good to know a couple of basic command line tools. The solution below uses the command grep, which is used to find lines in textfiles. I've installed UnxUtils on my Windows machine (to save my sanity, some things are just to painful to do other ways), which contains grep and lots of other quality tools. UnxUtils can be found at http://unxutils.sourceforge.net/.

Assuming you only have comments on their own line, this might be the simplest way:
B4X:
grep -v "^[[:space:]]*'" code_with_comments.bas > code_without_comments.bas

Explanation:
  • grep - the program we're using
  • -v - only show lines NOT matching what we're asking for below
  • "^[[:space:]]*'" - this is a language in itself, but the short explanation for what we're searching for is "find me all lines that start with ', and it's ok if we have whitespace first"
  • code_with_comments.bas - your code with comments
  • > - don't bother showing us the result, just pour it into the file we're about to tell you about
  • code_without_comments.bas - the resulting file

So this is a perfectly safe command to run, as long as you make sure you're using a new filename as the last thing on the line. (If you're using a previously used filename, that file will be overwritten.) Then you can compare that to your original file. If you like the result, just delete the original file and rename the new file to take the old ones place.

Repeat if you want to do this with more than one file. (If you're feeling more adventurous, have lots of files to do this for and feel ok to automatically do the replacement in the existing files - do a backup of your project first! - you should google the command sed.)
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
Sandman: This should work. I'd suggest outputting the uncommented files with the same file name but in a different directory so it will compile with no changes to the project.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I'd suggest outputting the uncommented files with the same file name but in a different directory
Yep, sure, that would also work fine. Better double check the output name though so you're actually writing the output to the new dir - don't wanna overwrite the commented file...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…