0

I really need help fixing this line of my code, I keep getting these two errors:

First Error: array required, but String found if(x.length() == 0 && y.length() > 0 && y[0] == "*")

Second Error: no suitable method found for replace(int,int) String newY = y.replace(0,1); any help would be appreciated

//Second string is empty and there is wildCard character
if(y.length() == 0 && wildCard)
{
    return true;
}
if(x.length() == 0 && y.length() > 0 && y[0] == "*")
{
    String newY = y.replace(0,1);
    return match(x, newY, true);
}
1
  • newY is a String, and your method match requires an array. Commented Mar 30, 2013 at 22:58

2 Answers 2

3

y[0] is for arrays; use y.charAt(0) for strings instead. Furthermore, compare it with '' (the character), and not with "" another string.

Sign up to request clarification or add additional context in comments.

4 Comments

thank you so much, but how do i I do this in Java String newY = y.remove(0,1); <----- this doesnt seem to work in java any help? { String newY = y.replace(0,1); return match(x, newY, true); }
So I'm assuming you meant replace: String newY = y.replace(0, 1) won't work, because 0 and 1 are int. Try replace('0', '1'), with chars.
wanted to remove string y between 0-1
Then you can use substring. If you want to remove between 0 and 1 inclusive, then you want the string after the second position; just do y.substring(2). If you want to remove between 0 (inclusive) and 1 (exclusive), then do: y.charAt(0) + y.substring(2).
3

In

if(x.length() == 0 && y.length() > 0 && y[0] == "*")

The "*" is a String, not a character.

Also, the y[0] does not work with Strings in Java, only arrays. That's likely your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.