on 09-23-2010 8:09 PM
XI Experts,
It is a easy question but I don't the answer:-)
How to use "Contains" in the UDF?
I need to find out particular string in the long string, it can be at any position of the string..for e.g
I need to find "TEST" in the given string, how can I do this in UDF?
Marks will be given:-)
Thank you
MP
the other option could be the standar function indexOf which return the position where the second string if found for the first time in the fisrt string
"Hello World"---->
-
> IndexOf-----> Return 6
"World------->
Take in mind that function is key sensitive so if you look for "world" the result will be "-1"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Better solution is to use indexOf(). If the string is not present, it will return -1.
Example:-
String str1 = "This is a string";
String str2 = "string";
int result_index = str1.indexOf(str2);
if (result_index != -1)
{
your logic
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is standard function that take two strings, retun index number if the second one contains first one. otherwise return -1
The result is similar like java function IndexOf();
If you really need to code UDF, you can also code like a.IndexOf("b") to check if b inside a, or use contains like previous reply
Regards
Liang
Edited by: Liang Ji on Sep 23, 2010 10:13 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
see this clear example.
public class StringContainsExample {
String string="java string contains character";
boolean checkContains1=string.contains("ja");
boolean checkContains2=string.contains("xa");
System.out.println("check contains string 1 :"+checkContains1);
System.out.println("check contains string 2 :"+checkContains2);
}
Output
check contain string 1 :true
check contain string 2 :false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.