on 10-31-2008 11:06 AM
Hello All
I am trying to write an UDF which can count the number of occurances of charecter ' in a string and fives the result as number of occurances - 3 . For example if the char ' is present 20 times in a string , I want the result to be 17.
Could you help me in creating this UDF please, I am a beginner to Java.
Thank you
Hi,
Try this code,
int count = 0;
String str;
for(int i=0; i=a.strlength();i++)
{
if (a<i> = 'a')
{
count = count + 1;
}
}
count = count - 3;
str = integer.toString(count);
return str;
Regards,
Sreeni
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sreeni ,
I tried you code , but it has some compilation errors ,
The cod ei used is
//write your code here
int count = 0;
String str;
for(int i=0; i=input.strlength();i++)
{
if (input = '\'')
{
count = count + 1;
}
}
count = count - 3;
str = integer.toString(count);
return str;
Just as you suggested ,
for it I got these errors
incompatible types
found : int required: boolean
for(int i=0; i=input.str.length();i++)
cannot resolve symbol
symbol : variable str
location: class java.lang.String
for(int i=0; i=input.str.length();i++)
incompatible types
found : java.lang.String
required: boolean if (input = '\'')
cannot resolve symbol
symbol : variable integer
location: class com.sap.xi.tf._MMPOFileToPayload_
str = integer.toString(count);
cheers
Hi,
Just Change double quotes with single quotes..
like this
if (input.charAt(i) == 'a')
Use this code
String search ="";
search = "a";
int count = 0;
for (int i = 0 ; i< input.length();i++)
{
if (input.charAt(i) == 'a')
count = count + 1;
}
int res = count - 3;
count = 0;
String value = "";
value = integer.toString(res);
return value;
Regards
Aashish Sinha
Edited by: Aashish Sinha on Oct 31, 2008 1:12 PM
Use this code,
public String tst(String a,Container container){
//write your code here
int count = 0;
for(int i = 0; i<a.length();i++)
{
if (String.valueOf(a.charAt(i)).equals("a"))
count = count +1;
}
count = count -3;
return Integer.toString(count);
}
Here I have checked for the occurance of character 'a' if u need any other character change it accordingly...
This will work for sure...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Lets say input string is input = "aashish sinha"
String search ='"";
search = "a";
int count = 0;
for (int i = 0 ; i< input.length();i++)
{
if (input.charAt(i) == "a")
count = count + 1;
}
int res = count - 3;
count = 0;
String value = "";
value = integer.toString(res);
return value;
Regards
Aashish Sinha
Edited by: Aashish Sinha on Oct 31, 2008 12:15 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
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.