Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:13:14+00:00 2026-06-13T12:13:14+00:00

public static String convert(String str) { if (str.equals(# )) System.out.println( ); Pattern pattern =

  • 0
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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:13:15+00:00Added an answer on June 13, 2026 at 12:13 pm
       public static String convert(String str)
     {
       if (str.equals("# "))
          System.out.println(" ");
       Pattern pattern = Pattern.compile("(#+[^#]+)");
       Matcher matcher = pattern.matcher(str);
    
       while (matcher.find())
       {
           boolean append_p = false;
           char carac;
            for(int i = 0; i < str.length(); i++){
           if(Character.isLetter(str.charAt((i)))){
               if (Character.isUpperCase(str.charAt(i)))
               {
                  System.out.print("<p>");
                  append_p = true;
                  break;
               }
           }else{
               append_p = false;
           }
       }
          String str1 = matcher.group(1);
          if (str1.replaceFirst("#+", "").length() == 0 || str1.replaceFirst("#+", "").matches("[\\s]+"))
             continue;
          int n = str1.length() - str1.replaceFirst("#+", "").length();
          System.out.print("<h" + n + ">" + str1.substring(n) + "</h" + n + ">");
          if(append_p == true){ System.out.print("</p>"); append_p = false;}
       }
       if(Character.isUpperCase(str.charAt(0)){
          System.out.println("<p>"+str+"</p>");
       return ("");
     }
    

    this will test if the first character is an upper case letter and append/prepend <p></p>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the method: public static String CPUcolor () { System.out.println (What color am I?)
So now I have this method: public static String convert(String str) { if (str.equals(#
I started writing this algorithm: public static String convert(String str) { if (str.equals(# ))
So I have these two functions, public static string[] CharToHex(string str, string prefix, string
Consider below code: public class Test{ public static void main(String str[]){ B b =
I have a simple function converts date to java.sql.date . public static java.sql.Date getSqlDate(String
public static string RatingCalculator(int input) { if (input < 10) { return string.Empty; }
public static string GetCurrentEmployeeName() { return db.Employees.SingleOrDefault( c => c.NTUserName == CurrentUsername() ).Last_First; }
public static string TimeLine2(this HtmlHelper helper, string myString2) { StringBuilder myString3 = new StringBuilder();
public static String doCensor(String toCensor) { Object[] aobj; int l = (aobj = toCensor.toCharArray()).length;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.