Skip to main content
Question

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

  • November 2, 2016
  • 6 replies
  • 393 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

todd_davis
Supporter
Forum|alt.badge.img+21
  • Supporter
  • November 2, 2016

Best to use stringconcatenator.


  • Author
  • November 2, 2016

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


todd_davis
Supporter
Forum|alt.badge.img+21
  • Supporter
  • November 2, 2016

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"


  • Author
  • November 2, 2016

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?


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • November 2, 2016
edttom wrote:

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.

 

 


arekpierchala
Contributor
Forum|alt.badge.img+1

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings