### Inline Java Ext Library jSoup/2

B4J UI Application - Inline Java jSoup showing how to strip HTML Tags from a String
Reference jSoup: http://www.jsoup.org
Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
'External lib
#AdditionalJar: jsoup-1.8.1
End Region
`Sub Process_Globals
Private Const CAPPINFO As String = "B4JHowTo - Inline Java jSoupEx v20150711"
Private fx As JFX
Public joInlineJava As JavaObject = Me
End Sub`
'Start the app
'Strip Html tags
`Sub AppStart (Form1 As Form, Args() As String)
Log(CAPPINFO)
Dim s As String = "

some text

another text

"
s = joInlineJava.RunMethod("stripHtml", Array(s))
Log(s)
Dim s As String = "

some text

\n

another text

"
s = joInlineJava.RunMethod("stripHtml2", Array(s))
Log(s)
Log(s.Replace("\n ", CRLF))
End Sub`
'Example stripping html tags from string
'Returns stripped string
If JAVA
import java.util.List;
import org.jsoup.Jsoup;
//Stripping as one line
//String s = "

some text

another text

";
public static String stripHtml(String s) {
String stripped = Jsoup.parse(s).text();
//System.out.println(stripped);
return stripped;
}
//Stripping multiple lines depending by replacing \n to CRLF
//String s = "

some text

\n

another text

";
public static String stripHtml2(String s) {
String r = "";
for (String line : s.split("\n")) {
String stripped = Jsoup.parse(line).text();
r = r + stripped + "\n";
//System.out.println(stripped);
}
return r;
}
End If

Changed: , Category: Inline Java, File: T6C201M1474.htm, ID: 1474