on 11-09-2011 8:06 AM
Hi
I have to remove leading zeroes from an alphanumeric string. I used the code in this link
http://wiki.sdn.sap.com/wiki/display/Java/RemoveLeadingandTrailingZerosfroma+String
if (str == null){
return null;}
char[] chars = str.toCharArray();
int index = 0;
for (; index < str.length();index++)
{
if (chars[index] != '0'){
break;}
}
return (index == 0) ? str :str.substring(index);
}
I am using XI 7.1 and I am getting errors when I trried to run it in Message Mapping
Java:90: 'class' or 'interface' expected public void init(GlobalContainer container) throws StreamTransformationException{ ^
java:130: 'class' or 'interface' expected public static void main(String[] args) throws Exception(); st.testExecute(); }
java:131: 'class' or 'interface' expected }
Java:132: 'class' or 'interface' expected ^ 4 errors
Any idea why I am getting this error ?
Regards
use below code snippet
s is input argument to UDF.
String s1=s.replaceFirst("^0+(?!$)", "") ;
return s1;
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ajit,
There is no standard mapping function to check the alphanumeric. You need to write a small UDF to do this function.
here is small code: this UDF takes one input(inString) value for which we check whether it is numeric or alphanueric
catch(Exception e)
{
result = false;
return result.toString();
}
Above UDF gives true is inString is Numeric or false if it's not numeric (it means, inString is Alphanumeric).
Also, check the below thread:
Link: [http://forums.sdn.sap.com/thread.jspa?threadID=2058429&messageID=10728460#10728460]
Thanks,
RK
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Java:90: 'class' or 'interface' expected public void init(GlobalContainer container) throws StreamTransformationException{ ^
java:130: 'class' or 'interface' expected public static void main(String[] args) throws Exception(); st.testExecute(); }
java:131: 'class' or 'interface' expected }
Java:132: 'class' or 'interface' expected ^ 4 errors
Any idea why I am getting this error ?
You should comment out the main method. Re-test and get back to us.
Regards,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ajith,
first you need to pass your string as a input, in your case argument missing.
try using format number standard fuction.
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ajith,
For this single line code is enough.
create simple UDF and take 2 input values, first one is the original string and second one is the leading removal/delete value, then use the below code in that UDF.
return(inputStr.replaceFirst("^"value"+","")); //here inputStr is the actual string and value is the removal/delete parameter
Regards,
Venkata Ramesh
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.