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 6233069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:13:56+00:00 2026-05-24T10:13:56+00:00

Is there a fast way to search for string in another string? I have

  • 0

Is there a fast way to search for string in another string?

I have this kind of a file:

<br>
Comment EC00: 
<br>
The EC00 is different from EC12 next week. The EC00 much wetter in the very end, which is not seen before.
<br>

<br>

<br>
Comment EC12: 
<br>
The Ec12 of today is reliable. It starts cold, but temp are rising. From Sunday normal temp and wet, except for a strengthening high from SE in the very end.
<br>

I have deleted all the <br>‘s and I will be searching for a string like “Comment EC12:” to retrieve what comes after:

The Ec12 of today is reliable. It starts cold, but temp are rising. From Sunday normal temp and wet, except for a strengthening high from SE in the very end.

Or maybe it could be a better idea to leave all the <br>‘s so that I will know at least where to stop reading the lines..

P.S. These comments might have multiple occurences in the document.

EDIT:
I think that this solution would be ok for finding the occurences, at least a good place to start..
This is the last version, it works for me very good, because I know what in the HTML will be static and what is not.. But for those, who would like to do something simmilar, you can rewrite first two loops in the simmilar way as the last one(instead of ‘if’ using while – going down the lines of the text file)

                      StringTokenizer parser = new StringTokenizer(weatherComments);
                      String commentLine = "";
                        String commentWord = "";

                       while (parser.hasMoreTokens()) {
                            if (parser.nextToken().equals("Comment")) {
                                String commentType = parser.nextToken();
                                if (commentType.equals(forecastZone + ":")) {
                                    parser.nextToken(); //first occured <br>
                                    commentWord = parser.nextToken();
                                    while(!commentWord.equals("<br>")){
                                        commentLine += commentWord + " ";
                                        commentWord = parser.nextToken();
                                    }
                                commentLine += "\n";
                                System.out.println(commentLine);
                                }
                            }
                        }

P.P.S.
Before downloading a lot of libraries to make your code look smaller or to understand things easier, think first how to solve it yourself

  • 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-05-24T10:13:57+00:00Added an answer on May 24, 2026 at 10:13 am

    You can try to simply use indexOf():

    String html = ...;
    String search = "Comment EC12:";
    int comment = html.indexOf(search);
    if (comment != -1) {
      int start = comment + search.length();
      int end = start + ...;
      String after = html.substring(start, end);
      ...
    }
    

    The problem is to find the end of the text. So it may be useful not to replace the <br> and split the HTML on the tags:

    String html = ...;
    String[] parts = html.split("\\p{Space}*<br>\\p{Space}*")
    for (int i = 0; i < parts.length; i += 2) {
      String search = parts[i];
      String after = parts[i + 1];
      System.out.println(search + "\n\t" + after);
    }
    

    The example will print the following:

    Comment EC00:
        The EC00 is different from EC12 next week. The EC00 much wetter in the very end, which is not seen before.
    Comment EC12:
        The Ec12 of today is reliable. It starts cold, but temp are rising. From Sunday normal temp and wet, except for a strengthening high from SE in the very end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a fast way to search/scan the memory of a process for a
Is there a fast/efficiency way to check if a table is empty? DECLARE @StartEndTimes
I need to check in some fast way if there is any text nodes
Can anyone recommend a fast way to sort the contents of a text file,
Hi so I need some FAST way to search for a word in a
Is there any fast way to get all subarrays where a key value pair
Is there a fast way in the Address Book framework on the iOS platform
I have a table that's holding metadata for entrys from another table. The metadata-table
Is there a fast algorithm for finding the Largest Common Substring in two strings
Is there any fast implementation of cryptographically secure pseudorandom number generator (CSPRNG) for C#

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.