cancel
Showing results for 
Search instead for 
Did you mean: 

Script to replace Slash with underscore

mvalicpi40
Explorer
0 Kudos

Hi Team,

Can anyone help me with a groovy script to replace / with _

Input: HD2781/01

OutPut: HD2781_01

Regards,

Mastan

Accepted Solutions (1)

Accepted Solutions (1)

venkateswaran_k
Active Contributor
0 Kudos

Hi

You can use as - replaces back slash..

<yourStringVariable>.replace("\\", "_")

Regards,

Venkat

mvalicpi40
Explorer
0 Kudos

Hi,

below code worked for me

import com.sap.it.api.mapping.*;

def String replaceSlash(String MPN){

def replace = MPN.replace("/", "_")

return replace

}

Answers (1)

Answers (1)

PriyankaChak
Active Contributor
0 Kudos

Hi Mastan,

import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {

def input = message.getBody(String).replaceAll('/','_')

message.setBody(input)

return message

}

Regards,

Priyanka

mvalicpi40
Explorer
0 Kudos

Hi Priyanka,

thank you for your reply.

Seems above code is for outside of Message mapping.

I need script inside MM which replaces / with _ when a field contains Slash(/)

Regards,

Mastan

PriyankaChak
Active Contributor

You can directly use standard function to replace within MM.

https://answers.sap.com/questions/10530180/explain-replacestring-functions.html