Java regex Android How to find any text in the String [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi I have some string.
String cos = "Something I do not know ThisIWantToFind Something I do not know";
And how I can find this with regex ?
I tried with:
result = cos.matches("(.*)ThisIWantToFind(.*)");
and
result = cos.matches("(.*?)ThisIWantToFind(.*?)");
but this not work :(

without regex
case sensitive
String cos = "Something I do not know ThisIWantToFind Something I do not know";
if (cos.indexOf("ThisIWantToFind") > -1)
{
// found
}
not case sensitive
String cos = "Something I do not know ThisIWantToFind Something I do not know";
if (cos.toUpperCase().indexOf("ThisIWantToFind".toUpperCase()) > -1)
{
// found
}

You want to know if the regex is in the string or the position of the regex in the string?
for the first one, I guess this should work ..
boolean result = cos.matches(".*ThisIWantToFind.*");
?

Related

'Not a statement', '; expected' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am getting both these errors (on the marked line) with the following code in java;
String data[] = file.getInput();
while(data[0] != "X"){
String ID = data[0];
String firstName = data[1];
String lastName = data[2];
data[] = file.getInput(); //errors occurr here
}
Note that file.getInput() is a method that returns an array of Strings from a CSV file using the InputReader.
Just remove the [] from data.
data = file.getInput();
Remove the ‘[]’ from data :
data = file.getInput(); ‘Do the statement like this’

I need to get two numbers of a string like like this "5+7", but when im using .split(\\+) only get the first, how can i get both? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
String x = "5+7";
String []n = x.split("\\+");
System.out.println(n[0]); // =5
System.out.println(n[1]); // =\
Your code should work fine, but I'd try to make it more robust:
String test = "5 + 7";
String[] tokens = test.split("\\s*\\+\\s*");
for (String token : tokens) {
System.out.println(token);
}
The \\s* will allow for possible white-space between the numbers and the + char.
use
x.split("[+]");
That will split it correctly.

Strings in ternary operators interacting with numbers [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
If I have an if statement that includes a string like this:
double GUInumber1 = ((GUInumber1 >= 0 || <= 0)? Double.parseDouble(GUIfirstNumber) : 0);
('GUIfirstNumber' is the string)
Why does it come up as a error? Do I need brackets somewhere, do I need to use 'If/else' instead?
Supposedly my compiler says it does not recognize or (||), is this supposed to be something else or does this work in a completely different way.
Any help on this situation would be appreciated, also, if you need to know or are just wondering why I want to make a if statement for a string its because whenever I try to put in a letter instead of a number Java crashes, I'm hoping I could get this to alternatively solve the situation instead.
EDIT:
Solved, had to remove 'or' statements and alternatively make more else statements instead.
This expression (GUInumber1 >= 0 || <= 0) is not correct.
You will need something on both sides of the <= operator.

Why am I getting an invalid character constant for the '[ in Java? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
There is an issue with for the '[ right in front of the data-testing-id and I am not sure why. Any help is appreciated.
for (int i = 1; i < 1001; i = i + 1) {
if(driver.findElement(By.cssSelector('[data-testing-id="data-id1"]'))!= null){
System.out.println("Element is Present");
}else{
System.out.println("Element is Absent");
}
}
Java String(s) can't be done in single quotes. This,
By.cssSelector('[data-testing-id="data-id1"]')
Should be (escaping the double quotes),
By.cssSelector("[data-testing-id=\"data-id1\"]")
or with single quotes inside the double quotes, like
By.cssSelector("[data-testing-id='data-id1']")
You should use
"[data-testing-id=\"data-id1\"]"
for(int i = 1; i < 1001; i++)
i++ is another way to add an increment of 1 to i for each loop... And a wee bit easier than typing (i = i + 1)
I am new to Java and not sure if that was worth your time reading, but I think its pretty cool and might make your code prettier...

Illegal format string in TextIO.putf() method aka wrong Array Type? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I guess its a rather simple question but i just cant find my mistake.
int[] myIntArray = new int[20];
myIntArray[5] = 5;
int a = myIntArray[5];
TextIO.putf("arr[i]: d%",a );
The error I get is Illegal format string in TextIO.putf() method.
So I assume the value at the index 5 is not an int?
The error message says exactly what the problem is: your format string is wrong. You probably meant %d (or better yet, %d%n to add a newline).
The format string elements are in the form
%[modifiers]type
not
something%
Change d% to %d.

Categories