on 03-17-2011 7:54 PM
I'm using the Seeburger ReplaceString module. I need to search for "~" (Tilde) and replace it with a carriage return.
Any words of wisdom?
>> I think regex is the better route....
Try udf and do this...
Note: If you want java mapping , I will modify below code and send you again...
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public String regExStringReplace(String var1, Container container) throws StreamTransformationException{
String REGEX = "~";
//String var1 = "aa~fooaabfooabfoob";
String REPLACE = "\n";
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(var1); // get a matcher object
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, REPLACE);
}
m.appendTail(sb);
return sb.toString();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a possibility, the issue is that it turns the carriage return into something unique -- a different way of handling the search and replace.
I'm really trying to do this with the Seeburger ReplaceString module. There is an option to use a regex, but I have not been able to find any specific documentation how Seeburger exepcts the regular expressions to be passed.
I may have to use this method, but certainly would not be my preferred method.
Below is the module configuration for Seeburger ReplaceString module
Module Name : localejbs/Seeburger/ReplaceString
Module Key : rep
Modulekey Parametername ParameterValue
rep sourceDest MainDocument
rep targetDest MainDocument
rep searchString "Search string"
rep replaceString "replace string"
rep regularExpression true
I gave up trying to do this with the module and resorted to using a Java Map.
---
package UNDISCLOSED;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.sap.aii.mapping.api.*;
import java.io.ByteArrayOutputStream;
public class CharacterTranslation extends AbstractTransformation {
public void transform(TransformationInput in, TransformationOutput out)
throws StreamTransformationException {
// Read Dynamic Configuration from Input Stream
// ************************************************************************************************************
// Transfer Input Stream to Output Stream without further modifications
// ************************************************************************************************************
InputStream inStream = in.getInputPayload().getInputStream();
OutputStream outStream = out.getOutputPayload().getOutputStream();
int c = -1;
try
{
// Read incoming stream into string
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((c = inStream.read()) != -1)
baos.write(c);
String inStr = baos.toString("UTF-8");
// Replace Prolog
String outStr;
outStr = inStr.replaceAll( "
|", "@" );
outStr = outStr.replaceAll( "~", "\n" );
outStr = outStr.replaceAll( "`", "-" );
// pass the payload to PI
outStream.write(outStr.getBytes("UTF-8"));
} catch (IOException ioe) {
throw new StreamTransformationException
("Exception in Java mapping occured while reading incoming message. The exception is: " + ioe.getMessage());
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is close, but not quite there yet. The first post dealt with a Java Mapping --- I'm trying to avoid that if possible. It's not that we can't do that, but we are already replacing characters using ReplaceString.
The challenge with this specific character is that the Carriage Return does not have a "quoteable" string like adding accent mark character substitutions, at least none that I am aware of.
Looking back at the documentation, I think the "regex" function might be a better route but I don't see any examples to work off of.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.