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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:01:30+00:00 2026-05-28T17:01:30+00:00

startsWith(string prefix) requires two strings and searches if both strings start with the same

  • 0

startsWith(string prefix) requires two strings and searches if both strings start with the same value, is there a way too modify startsWith(string prefix) to search one string for re-occuring characters?

Lets say

String str = "MANAMA";

I want to be able to search that string using startsWith() and endsWith() or some variation to determine whether or not the prefix or suffix of the string are the same. The only problem is those methods search two strings to see if they have matching suffix’s or prefix’s

startsWith(string prefix) does this :

    String str1 = "MANAMA";
    String str2 = "PANAMA.";


    // Sets what characters to search for from above strings
    String startStr = "MA";

    // Searchs for startStr in strings
    boolean starts1 = str1.startsWith(startStr);
    boolean starts2 = str2.startsWith(startStr);

    // Display the results of the startsWith calls.
    System.out.println(starts1);
    System.out.println(starts2);

endsWith(string suffix) does :

    String str1 = "MANAMA";
String str2 = "PANAMA.";


// Sets what characters to search for from above strings
String endStr = "MA";

// Searchs for startStr in strings
boolean ends1 = str1.endsWith(endStr);
boolean ends2 = str2.endsWith(endStr);

// Display the results of the endsWith calls.
System.out.println(ends1);
System.out.println(ends2);

Is there a way to modify or a different method to be able to search WITHIN one string instead of searching two strings for endStr and startStr?

  • 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-28T17:01:32+00:00Added an answer on May 28, 2026 at 5:01 pm

    Not sure if I’m understanding your question correctly but you can use endsWith() and startsWith() on the same string. For example:

    String line = "MANAMA";
    String edge = "MA";
    
    boolean check = line.startsWith(edge) && line.endsWith(edge);
    // returns true if the string starts and ends with "MA"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a nice linqy way of splitting a FormCollection into a Dictionary<string,string> that
I'm using startswith reg exp in Javascript if ((words).match(^ + string)) but if I
String string1 = abCdefGhijklMnopQrstuvwYz; String string2 = ABC; I had been using string1.startsWith(string2), which
First, a little background. I have strings that resemble the following: ((Foo.Bar.StartsWith(A)) && (Foo.Bar.EndsWith(B)))
Is this possible? Given that C# uses immutable strings, one could expect that there
I have a javascript function: string.prototype.startsWith = function(str) { return (this.indexOf(str) === 0); }
Python has string.startswith() and string.endswith() functions which are pretty useful. What NSString methods can
In Java is there a way to find out if first character of a
With Scala's pattern matching I would like to confirm not only that two String
Possible Duplicates: Splitting in string in JavaScript javascript startswith Hello I have a string

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.