public
class
Sample {
public
static
void
main(String a[]){
String str =
"GHj��PL����AM�"
;
System.out.println(str);
str = str.replaceAll(
"[^\\p{ASCII}]"
,
""
);
System.out.println(
"After removing non ASCII chars:"
);
System.out.println(str);
}
}
System.out.println("here dec after con is "+decryptedContent.replaceAll("[^\\p{ASCII}]", "").trim());
OUTPUT
After removing non ASCII chars:
GHjPLAM
Remove HTML Tags
public
class
HtmlTagRemover {
public
static
void
main(String a[]){
String text =
"<B>Remove tags<\\B>"
;
System.out.println(text);
text = text.replaceAll(
"\\<.*?\\>"
,
""
);
System.out.println(text);
}
}
OUTPUT
"<B>Remove tags<\B>
Remove tags
public class multipleSpaces {
public static void main(String[] args) {
String str = "String With Multiple Spaces";
StringTokenizer st = new StringTokenizer(str, " ");
StringBuffer sb = new StringBuffer();
while(st.hasMoreElements()){
sb.append(st.nextElement()).append(" ");
}
System.out.println(sb.toString().trim());
}
}
public static void main(String[] args) {
String str = "String With Multiple Spaces";
StringTokenizer st = new StringTokenizer(str, " ");
StringBuffer sb = new StringBuffer();
while(st.hasMoreElements()){
sb.append(st.nextElement()).append(" ");
}
System.out.println(sb.toString().trim());
}
}
No comments:
Post a Comment