cancel
Showing results for 
Search instead for 
Did you mean: 

Seeburger ReplaceString

Former Member
0 Kudos

I'm using the Seeburger ReplaceString module. I need to search for "~" (Tilde) and replace it with a carriage return.

Any words of wisdom?

Accepted Solutions (0)

Answers (2)

Answers (2)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>> 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();

}

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Thats right....is there a method to insert a non-display character....for example a carriage return.

My source file uses an EOL character (). II need to replaced "" with carriage returns.

Edited by: GerryS on Mar 18, 2011 12:07 PM - characters in message made it unreadable.

Former Member
0 Kudos

Try this.

SearchString = '~'

replaceString = '

' or '\u000A'

Former Member
0 Kudos

The "\n" options you propose didn't occur to me.

Both were unsuccessful. Both were treated as strings. So my "~" became "\n"

Former Member
0 Kudos

Try using Binary mode:

binaryMode: true

replaceString: "0D"

searchString: "7E"

The first without quotes, the others with the one I wrote.

Regards,

giuseppe

Edited by: Giuseppe Sinatra on Mar 22, 2011 3:56 PM

Former Member
0 Kudos

Nope. Still nothigng.

Where did you find the "binaryMode"flag?

This does not exist in the documentation I have.

Former Member
0 Kudos

I don't think it's documented by Seeburger, but for me it worked.

I used the following on See release 2.1.4 with expected result:

binaryMode true

replaceString "270D0A"

searchString "270A"

Former Member
0 Kudos

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());

}

}

}

deepak_shah
Contributor
0 Kudos

Hi Gerry,

Please refer below links.

Hope this helps.

Regards,

Deepak.

Former Member
0 Kudos

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.