Question

How to add text in front of string? (StringReplacer)

  • 2 November 2016
  • 6 replies
  • 84 views

Hi all,

I'm trying to update a certain string by adding text in front of it.

 

Any string that starts with a number should be updated by placing a certain part of text in front of it.

 

(in below example adding "EVS" in front of it.) Any string that does not start with a number should remain untouched.

What I have:

Attribute: "locationName"

142736-1

 

Testlocation1

 

What I want:

 

EVS142736-1

 

Testlocation1

Many thanks,

Ed


6 replies

Userlevel 1
Badge +12

Best to use stringconcatenator.

Hi @todd_davis, thanks for the suggestion.

 

Unfortunately I'm not familiar with the StringConcatenator, can you perhaps show me what the transformer settings would look like?

Thanks

Userlevel 1
Badge +12

Assumed for this example that 142736-1 is in an attribute called "Code" and that EV is constant for all feature. The resultant attribute is stored in the attribute "_result"

I have updated the first post with more info / example.

The attribute name is "locationName"

 

- If a string starts with a number it should be updated to "EVS + original value"

 

- If a string starts with text it should be left untouched.

 

 

Can the StringConcatenator handle this?

Userlevel 2
Badge +17

I have updated the first post with more info / example.

The attribute name is "locationName"

 

- If a string starts with a number it should be updated to "EVS + original value"

 

- If a string starts with text it should be left untouched.

 

 

Can the StringConcatenator handle this?

I would use the AttributeCreator with Conditional Value setting.

 

If "@Value(locationName)" Contains Regex ^\\d Then "EVS@Value(locationName)"

 

Else <do nothing>

 

The regular expression ^\\d matches a digit at the head of the string.

 

 

Badge

1. Use SubstringExtractor to get first character of the string

2. Use AttributeValidator to test above character type: 'rule configuration' = integer

3. Use StringConcatenator add specified string prefix to above validated records

Reply