Skip to main content

Hi

 

 

I'm sure I should get this, but I seem to have a mental block, maybe Friday afternoon related. I have a string attribute where some of the features contain a comma as the last character which I want to get rid of. What's the most effective way of doing this?

Thanks,

 

Riley

Well first you need to idenify which features contain the comma, the two ways I can think of is:

 

1: SubstringExtractor (-1,-1), tester (_substring = , )

 

2. StringSearcher (RegEx ,$)

 

 

Then a SubstringExtractor of (0,-2) on the features containing the comma.
I tried once the Attribute Trimmer. It worked for me to make a list or delet the features over the comma. 

 

Try it maybe! 
I need to correct my last comments. I meant AttributeSplitter. 

 

And for Delimiter and Format String just put a "," 

 

Hi Riley,

 

 

There are several ways. I would use the StringReplacer with this parameter setting.

 

-----

 

Text to Match: ,$

 

Replacement Text: <leave this paramter blank. i.e. empty stirng>

 

Use Regular Expressions: yes

 

-----

 

The regex ",$" matches to the last comma in a string. Replacing matched part with the empty string, that's equivalent to removing the matched part.

 

By default, the StringReplacer does nothing if there were no matched parts in the source string.

 

 

Takashi
Thanks for all the feedback. I got there in the end, after finally realising I had a character of whitespace after the comma breaking everything I'd tried!

 

 

For information, AttributeTrimmer wasn't suitable because there were multiple commas in the string and I only wanted to lose the end one - but I didn't explain that in my question.

Reply