on 10-28-2010 8:15 AM
Hi All
I am trying to count the number of appearance of my the string when so my UDF code is:
public String StringCounter(String BM_CH_ESS,Container container)
{
String searchFor = "BM_CH_ESS";
String value = null;
int searchLength = searchFor.length();
int Count = 0;
int index = 0;
for( int i = 0; i < value.length(); i++ )
{
index = value.indexOf(searchFor, i);
if ( index != -1 )
{
Count++;
i += index + searchLength;
}
}
return Count;
}
When ever press F7 I get the error below:
Basical I want to return a number of counts.
Source code has syntax error: C:/usr/sap/###/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map6dc873d0e26211df88c6000c2973cb67/source/com/sap/xi/tf/_MM_MDM_MATERIAL_TO_CATALOGUE_.java:500: incompatible types found : int required: java.lang.String return Count;
Can u please give some suggestions
Thanks
Yonela
> public String StringCounter(String BM_CH_ESS,Container container)
> int Count = 0;
> return Count;
You have to return a String, not an int.
Test your Java code with an external tool first:
/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yonela,
Why you are using for loop here? What's your actual requirement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ALL
Thanks for ur assistance, I managed to find the solution I went to my NetBeans aditor to write it:
I wanted to write a function like this to count the string appearance"
This is my below code:
public class Main {
/**
@param args the command line arguments
*/
public static void main(String[] args)
{
String inputString = "C:C:C";
String searchFor = "C";
int leng = searchFor.length();
int count = 0;
if(leng > 0)
{
int Index = inputString.indexOf(searchFor);
while(Index != -1)
{
count++;
Index = inputString.indexOf(searchFor, Index + leng );
}
}
System.out.println("Count = " + count);
}
}
Thanks inadvance
Yonela
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
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.