473,326 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

"contains" subString method

Is there any way (I know there is, I mean what is the way) to find a substring in a string without using contains(CharSequence cs) method, or any other java String library clas methods?
Aug 26 '08 #1
6 3594
Laharl
849 Expert 512MB
You can write a function to do it yourself. We're not going to do your homework for you...
Aug 26 '08 #2
After a bit of searching, I found this:


Expand|Select|Wrap|Line Numbers
  1. public boolean subString(char[] searchFor)
  2.     {
  3.         boolean foundIt = false;
  4.         for(int i=0;i<data.length;i++)
  5.         {
  6.             if(data[i] == searchFor[i])
  7.             {
  8.                 foundIt = true;
  9.             }
  10.         }
  11.         return foundIt;
  12.  
  13.  
  14.     }
but it returns an error Array.outofBounds at the line if(data[i] == searchFor[i]).

What does this error actually mean, and why does it occur?
Aug 26 '08 #3
Laharl
849 Expert 512MB
It means that one of the two arrays tried to access an element at an index that is outside the boundaries of the array, likely the searchFor array, as substrings are generally shorter than the string being searched. Also, that code will only check if the substring is found at the beginning of the search string. It also only actually matches one character.
Aug 26 '08 #4
JosAH
11,448 Expert 8TB
Is there any way (I know there is, I mean what is the way) to find a substring in a string without using contains(CharSequence cs) method, or any other java String library clas methods?
Why do you want to solve some String related question without using the most
obvious solution offered by that same String class? I see these silly questions
almost every day: multiply two numbers without using the multiplication operator *.
Find a substring in a String without using any String methods. Find a largest number
without using arrays etc etc. What's up with you folks?

kind regards,

Jos
Aug 26 '08 #5
Nepomuk
3,112 Expert 2GB
What's up with you folks?
I think the question is: "What's up with your teachers, folks?" ^^

Greetings,
Nepomuk
Aug 26 '08 #6
JosAH
11,448 Expert 8TB
I think the question is: "What's up with your teachers, folks?" ^^
No, the real question is: "why don't you just start reading your textbook?".

kind regards,

Jos
Aug 26 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
Hi, I'd like to adapt the query below to select records only if the Title field contains the string "Book" (as an example). I'd also like to use a different variant of the query elsewhere to...
1
by: Robin Tucker | last post by:
Hi, I would like to select records from a table where the following criteria hold: SELECT * from Mytable where field x "contains" string @X or
1
by: Shiperton Henethe | last post by:
Hi Anyone know how to do a MAILTO: such that the "BODY=" parameter contains carriage returns ? e.g. <A HREF="mailto:brochure@webwindows.co.uk?subject=Brochure Request&amp;body=Line1 blah blah...
0
by: Gianni Mariani | last post by:
I remember seeing a neat template specialization trick posted here a few months ago that allowed the detection of a type containing a member. After a day searching through google archives I come up...
4
by: Robert W. | last post by:
I've built a complex collection object from "System.Collections.CollectionBase". With regard to it, I have a question about the "Contains" method. At first I thought that "Contains" would...
4
by: Jake | last post by:
I need to know whether a request for a resource on our web server is coming from a particular affiliate domain or from another domain. In my testing, the HTTP_REFERER variable sometimes is empty....
7
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I need to check if a textbox (of size = 1) contains a specific value (character). I could say something like If txt1.text.equals("X") or txt1.text.equals("Y")... then... Ideally, I...
6
by: stanleyhsieh | last post by:
Hi all! I'm new here! I was wondering how I can check if a string contains only "A-Za-z0-9_" and ".". I tried the following code function check_validstring($check_validstring) { ...
4
by: seberino | last post by:
I'm looking over the docs for the re module and can't find how to "NOT" an entire regex. For example..... How make regex that means "contains regex#1 but NOT regex#2" ? Chris
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.