on 06-25-2008 12:42 PM
Hi,
What is the best way to insert a character at a special position in a string?
I have a string, i.e 123456789 (the length can vary) and I want to insert a "-" before the last three digits. The result should be 123456-789.
Is it possible to do this with standard functions?
Thanks for your help.
/Sten
HI,
Its not possible with existing Standard APIs in Mapping.
You need to go for UDf for this kind of requirment. Just one statement code will be fine
UDF Code
Cache Parameter -- Value
A--->TestUDF -
>B
//Write your code
return(A.substring(0,A.length()-3)"-"A.substring(A.length()-3,A.length()));
Thanks
Swarup
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
function myudf(String a, Container container)
{
int len=a.length();
char[[]] chars = str.toCharArray;
char[[]] chart = new char[[len+1]];
for(int i=0;i<len-3;i++)
chart[<i>]=chars[<i>];
chart[<i>]='-';
for(int j=len-3;j<len;j++)
{
i++;
chart[<i>]=chars[[j]];
}
String mystring = new String(chart);
return mystring;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
if this is ur input then u can do using std function.
though it is length method but will solve ur problem.
1) Use substring fucntion which will take 123456 value.
2) Use constant function with - value.
3) Use concat function and give 1 and 2 input.
4) Use substring function which will take 789 value
5) Use concat function and give 3 and 4 input.
chirag.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.