on 05-07-2014 1:39 PM
Hi All,
I have a scenario XI--IDoc.
Sender structure is having one field as Description which will carry some informatiom.I have to read the Summary Field and if I get XAA1:686,XAA2:767 or XAA3:876 like this inside this inside this field than I have substring and take those value individually than we have to map it accordingly.
You can consider all these value will come separated by ,(comma) and based of the sbustring we have to map it.
Thanks,
Rakhi
This works....assumptions are that XAA1, XAA2 etc is always 4 digit. thats it!
String str = var1[0];
int occ = str.indexOf(":");//gives first index of :
String filtered = str.substring(occ-4, str.length());
filtered = filtered.replace("or",",");
filtered = filtered.replace("OR",",");
String res[] = filtered.split("\\,");
for(int i=0; i <res.length; i++)
result.addValue(res[i].trim());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vinay,
See this text is not fixed "My Product is having this location" anything can come.We only know that we will receive some value like
XAA1:686
XAA2:767
XAA3:876
Might be these values are separated by comma or new line character(in next line).
We have to read the description and look for these values and if we get these value than we have to take it out and send it to target.
i took this string
fdgsdfgXAAD:345 XAA8t:456 dgdfgfdgfdgdfgg gfd gfdg fgd XAA1:686,XAA2:767, XAA8;456 or XAA3:876
(if you can make this input any more weird you are welcome ) i used regex
("\\b([X][A-Z]{2}[0-9][:][0-9]{3})\\b");
assumptions u are looking for a value anywhere with [X] means first letter is capital X though you can modify it by replacing that X in bracket by A-Z or whatever suits you then next two letters are CAPITAL A-Z then 4th is a digit then we will have : then next three digits \\b in the beggining and end show spaces tabs newlines etc so no need to be worried abt what separates than , or or it just looks for the value.
the code is
String str = var1[0];
Pattern p = Pattern.compile("\\b([X][A-Z]{2}[0-9][:][0-9]{3})\\b");
Matcher m = p.matcher(str);
while (m.find())
{
String s = m.group(1);
result.addValue(s);
}
hope it helps! you can try any string you want in youe PI ESR.
Hi Vinay,
Thanks Few things are working and few things are not.Can you Guide me.
Pattern p = Pattern.compile("\\b([X][A-Z]{2}[0-9][:][0-9]{3})\\b");
If you can Explain this.
Secondly,same mapping is need for different scenario but structure is change ..
Here,we have
A_2CMLNG_1: 89
A_2CKAKT_1: 685
A_2CYTOP_1: 745
Can you please check this one also.
1) Pattern p = Pattern.compile("\\b([X][A-Z]{2}[0-9][:][0-9]{3})\\b");
we made a regular expression here and compiled it and then we make a object of class Matcher to match this compiled regex with our string
Matcher m = p.matcher(str);
//then we traverse through the results given to us my this matcher in an array form that is a array constituted by the different values that match this regex.....we traverse this array (m.find()) until this condition is true.....
then we add the result into the display queue.
while (m.find())
{
String s = m.group(1);
result.addValue(s);
}
(\\b is actually \b to include this \(escape character) i had used two \\
this is the real regex
\b([X][A-Z]{2}[0-9][:][0-9]{3})\b
\b means a seprator between words it can be anything tab or whitespace or new line
() we use these brackets to mark a word or a unit here this XAA8:456 is a unit so we put the reg ex for this inside braces
[X] single value mentioned means that it searches for only the single X character
the very next [A-Z]{2} means that it searches for any character in range A-Z and this rule searches for combination of two letters that follow this rule it means that it searches for two characters together following this i.e adjacent like DF, GY if you think that you want to further drill down your pattern and you will always have AA you can replace this [A-Z]{2} by [A]{2} so it searches for XAA
now the next thing should be a digit so we have 0-9 if you dont specify {3} or any number in curly braces it assumes that you are searching for a single character
then [0-9]{3} digits in the end.....
use this site if you want to learn regex you can test your regex here
working on your next req
\b[A-Z][_][0-9][A-Z]{5}[_][0-9][:][ ][0-9]+\b
//padd the starting \b and ending \b with a extra \
ex A_2CMLNG_1: 89
assumption [\b space or new line or tab][Single capital alphabet][underscore][single digit][5 Alphabets in capitals][underscore][digit][: colon][space][anynumber of digits + symbol does that it means 1 or more digits][\b space etc]
\b[A-Z][_][0-9][A-Z]+[_][0-9][:][ ][0-9]+\b
if your req doesnt specify how many alphabets are there after A_2 for ex A_2DFDFDFDFD.....
then use + symbol like in the above variation.
Cheers
Vinay
i used this
fdsf sfdsf dsf dsf dsdsf ds A_2CMLNG_1: 89 ffewew werw A_2CMLNG_1: 89A_2CMLNG_1: 89
my Bad i missed the braces in the reg ex..... and also removed this \b now so it is more robust
here is the code works fine
String str = var1[0];
Pattern p = Pattern.compile("([A-Z][_][0-9][A-Z]{5}[_][0-9][:][ ][0-9]+)");
Matcher m = p.matcher(str);
while (m.find()) {
String s = m.group(1);
result.addValue(s);
}
Hi Vinay,
See my requirement is not getting fulfill.
Suppose
hsddhsgffgfsA_2CELNG_1: sdhgsjgsjhgjsagdhjsag1623461338346238
dfjgdsjfdhA_2CFAKT_1: 1134352342
dasdasdasdadA_2CPTOP_2: dfdfghsdgfjsgdjfhgsdjfgsh76457232
How I will take out.I only know that newline will be my next keyword value .I dont have the fixed length and data may contain alpha numberic value also.
Example:-
Consider Nothing will come before...
Input String:-
A_2CELNG_1:-adgsjgkchk26236564aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
A_2CFAKT_1: 1134352342kdhkfhjkgkjgjkhjkghkghkj
A_2CFAKT_1: 1134352342jfgfjfgghjf
Output:-
adgsjgkchk26236564aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(This value will go to A_2CELNG_1 at target
1134352342kdhkfhjkgkjgjkhjkghkghkj(this value will go to A_2CFAKT_1 target elemet and so on.
Hi Vinay,
Yes I also think the con's of this static code, We can add one more condition If the strings are in constant formats.For suppose compulsory the string starts with 3 alphabets(XAA) and numeric(1) some special character(:) again 3 numeric's (686). If the format is constant we can extended the code and can achieve the requirement.
Regards,
Anusha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rakhi,
I also face the same requirement, I written udf to remove tokenizers.
I hope below is your requirement ...
UDF Which i have used for removing prefix string and for identifying "x"
StringTokenizer st = new StringTokenizer(var1[0],", ");
while(st.hasMoreTokens()){
String str = st.nextToken();
if(str.startsWith("X")){
result.addValue(str);
}
}
Regards,
Anusha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Example:-
Consider Nothing will come before...
Input String:-
A_2CELNG_1:-adgsjgkchk26236564aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
A_2CFAKT_1: 1134352342kdhkfhjkgkjgjkhjkghkghkj
A_2CFAKT_1: 1134352342jfgfjfgghjf
Output:-
adgsjgkchk26236564aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(This value will go to A_2CELNG_1 at target
1134352342kdhkfhjkgkjgjkhjkghkghkj(this value will go to A_2CFAKT_1 target elemet and so on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i understand that
1)there is a new line after every A_2CELNG_1:-aaaaaaaaaaaaaaaadasd44aaaaaaaaaaaa etc
2)in the first string/line you have(1:-) :- instead of ":space" so can i conside either - or space can come
this is the code...first part is regex and inside the while loop as you dont want the whole value i am passing a substring from the first occurence of ":" + 2 till end....
you can give me more inputs with expected outputs if it doesnt help.
String str = var1[0];
// Pattern p = Pattern.compile("\\b([X][A-Z]{2}[0-9][:][0-9]{3})\\b");
Pattern p = Pattern.compile("([A-Z][_][0-9][A-Z]{5}[_][0-9][:][ -][a-zA-Z0-9]*)");
Matcher m = p.matcher(str);
while (m.find()) {
String s = m.group(1);
String filter = s.substring(s.indexOf(":")+2, s.length());
result.addValue(filter);
}
//java.util.regex.Pattern
//java.util.regex.*
//the limitation is in a case
/*
A_2CELNG_1:-aaaaaaaaaaaaaaaaA_2CELNG_2: 34343eee
when theres no separation between the two tokens it doesnt discriminate because it needs something to separate either a space or a new line.
*/
Your question is a bit unclear.
However if you want to split a string by comma and map them target field then below simple UDF should be fine.
String[] str = var1.split("\\,");
return str[var2];
where var1 is your input string with "," and var2 is an integer value(position)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Haresh,
See Description field will carry some string.
Example:- "My Product is having this location XAA1:686,XAA2:767 or XAA3:876" this is the complete string(just an example,I am not sure what will come it the field as prefix)after this we have to take the value XAA1:686,XAA2:767 or XAA3:876 and individually map it.
Suppose we have XAA1:686 than we will take this out from the complete string and map it with target field.
Pass this string to above UDF..
var1/input field = "My Product is having this location XAA1:686,XAA2:767 or XAA3:876:"
var2 a constant value "0"
Which will return "My Product is having this location XAA1:686"
if the text "My Product is having this location" standard then use replace string function to remove that which will give you XAA1:686.
i.e.
your input field -> UDF-> replace string->target field
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.