Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an API to minified a string ?

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where can find an API to minified a string or file, removing all empty space and \n ... , just like JQuery minified version ?

Thanks.
 
Prabhat Shankar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't have idea of API of that type but you can create your own minified API.

example is below for removing all empty space :

public static void main(String args[]){
String a="sdsdsd dddd fdsfdf";
a=a.replace(" ","");
System.out.println(a);
}
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to remove all whitespace, use String.replaceAll with a pattern like "\\s".
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Java libraries that solve the more general problem of reducing the size of JavaScript or HTML, try googling "java minify". There are several solutions out there. Personally I've never used any of them, so can't really recommend one over another. But as usual, Google is our friend.
 
Henry Wong
author
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And minification is a bit more than just removing whitespaces. First, only the whitespace that don't effect the functionality of a program is removed -- as removing the whitesppace in a string to be printed does affect the program. Second, comments must also be removed -- as removing carriage returns will chain the comments otherwise. This can get complex if you take into account comments within comments (for commenting out code), and commented out code with quotes with whitespaces. etc. etc. etc.

Henry
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically the best way would be to read the entire program flow into a memory model, then re-output that model leaving out what you don't want. Note that I said best, not easiest
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic