VMware Cloud Community
Lam_bui
Contributor
Contributor

Trim Characters Functionality

Hi,


I would like to ask what is the best way to trim characters in IB? For example, with string ' 1234-456789' , I only want to look the first 4 characters, how would I trim that out? I saw <stringModify>, but I don't see it has something like this?

Labels (1)
0 Kudos
8 Replies
michiel_dhont
Enthusiast
Enthusiast

You could use <setInstallerVariableFromRegex> to trim the first four characters:

 <setInstallerVariableFromRegEx>
   <name>trimmed</name>
   <text>1234-56789</text>
   <pattern> or ' ^(....).*</pattern>
   <substitution or  or 1<substitution/>
</setInstallerVariableFromRegEx>

0 Kudos
Lam_bui
Contributor
Contributor

Thanks, I was able to get it using something like this this:

<setInstallerVariableFromRegEx>     <name>value1</name>     <pattern>^(.*?)-(.*?)$</pattern>     <substitution> or  or 1</substitution>     <text>${value}</text>   </setInstallerVariableFromRegEx>
0 Kudos
AnonymousDefaul
Enthusiast
Enthusiast

It's great to hear you found a solution.

0 Kudos
Lam_bui
Contributor
Contributor

Hello,
Related to this optic, can you help me how I trim the first 6 or 7 char?

For example, if I want the first 7 char of  or ' 1234-5678-9012 or ' , which is  or ' 1234-56:. What would be the pattern and substitution logic? I've tried a few (like below) without success.

<pattern>^[0-9]{0,6}$</pattern>
0 Kudos
michiel_dhont
Enthusiast
Enthusiast

Can you try this pattern?

<setInstallerVariableFromRegEx>     <name>value1</name>     <pattern>^[0-9-]{0,7}</pattern>     <substitution> or  or 1</substitution>     <text></text>   </setInstallerVariableFromRegEx>
0 Kudos
AnonymousDefaul
Enthusiast
Enthusiast

Hi,

I've tried that, but I got the last 7 digit instead of the first 7.


Whole Narrow: 7746-1810-8801

Info: Narrow: 10-8801

0 Kudos
michiel_dhont
Enthusiast
Enthusiast

Hi Tam,

Sorry, I misunderstood your question. Could you try this instead:

<setInstallerVariableFromRegEx>     <name>value1</name>     <pattern>^([0-9-]{0,7}).*$</pattern>     <substitution> or  or 1</substitution>     <text></text>   </setInstallerVariableFromRegEx>
0 Kudos
Lam_bui
Contributor
Contributor

Thanks! this works for me.

0 Kudos