public static String convert(String str)
{
if (str.equals("# "))
System.out.println(" ");
Pattern pattern = Pattern.compile("(#+[^#]+)");
Matcher matcher = pattern.matcher(str);
while (matcher.find())
{
String str1 = matcher.group(1);
if (str1.replaceFirst("#+", "").length() == 0 || str1.replaceFirst("#+", "").matches("[\\s]+"))
continue;
int n = str1.length() - str1.replaceFirst("#+", "").length();
System.out.println("<h" + n + ">" + str1.substring(n) + "</h" + n + ">");
}
char carac;
carac = str.charAt(0);
if (carac >= 65 && carac <= 90)
{
System.out.println("<p>");
System.out.println(str);
System.out.println("</p>");
}
return ("");
}
How do I combine the while(matcher.find with this if(carac>= so I can get this output: < p> < h2> Decibel < /h2> < /p> for this input: ##Decibel??? (Instead of that, I get < h2> Decibel < /h2>. I’m making an algorithm in which “#” is recognized in the beginning of a sentence and turned into < h1> < /h1> or < hn> depending on the number of # present. After that, the algorithm recognizes if there’s a capital letter in the beginning of the sentence; if there is, it adds < p> < /p> at the beginning and end of the paragraph.
The big problem I’m having, is that I want to be able to combine both. so let’s say I would have #Appendix, I would like it to convert to < p> < h1> Appendix < /h1> < /p>
Thank you
this will test if the first character is an upper case letter and append/prepend
<p></p>.