Skip to main content
Solved

select more than one special character in a string....


tomjerry.vl
Forum|alt.badge.img

i have HSN field and some times those are having special characters, if it is not having any special character and it having single special character no need to select.

 

But here which string having more than one special character then select.

Special characters: /-

HSN1-11-11-11/22/21-2/21/2-2/2

 

In above table i need to select on yellow highlighted data only \\

Best answer by erik_jan

I would use the StringLengthCalculator to calculate the original length of the string.

Then use a StringReplacer to remove all special characters.

Repeat the StringLengthCalculator and use an AttributeCretator to calculate the difference in length.

That will tell you the number of special characters.

Could also be done in one AttributeCreator using string functions like StringLength and ReplaceString in the Text Editor.

View original
Did this help you find an answer to your question?

12 replies

ebygomm
Influencer
Forum|alt.badge.img+33
  • Influencer
  • December 5, 2019

Are all non special characters numbers?


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • December 5, 2019

Hi @tomjerry.vl,

Please use a StringSearcher with the expression '[/-]' and Advanced - All Matches List Name set to '_matches'. THis will create a list of all the special character matches in the string.

Next, we want to find the features with more than one element in the list, which we can do with a ListElementCounter on the _matches{} list. Use a Tester afterwards to find _element_count > 1.


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • Best Answer
  • December 5, 2019

I would use the StringLengthCalculator to calculate the original length of the string.

Then use a StringReplacer to remove all special characters.

Repeat the StringLengthCalculator and use an AttributeCretator to calculate the difference in length.

That will tell you the number of special characters.

Could also be done in one AttributeCreator using string functions like StringLength and ReplaceString in the Text Editor.


tomjerry.vl
Forum|alt.badge.img
  • Author
  • December 5, 2019
erik_jan wrote:

I would use the StringLengthCalculator to calculate the original length of the string.

Then use a StringReplacer to remove all special characters.

Repeat the StringLengthCalculator and use an AttributeCretator to calculate the difference in length.

That will tell you the number of special characters.

Could also be done in one AttributeCreator using string functions like StringLength and ReplaceString in the Text Editor.

ok but too lengthy process


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • December 5, 2019
tomjerry.vl wrote:

ok but too lengthy process

To use just the one transformer (AttributeCreator) you can use this logic:

It will calculate the number of - and / characters in the test string.


tomjerry.vl
Forum|alt.badge.img
  • Author
  • December 5, 2019
erik_jan wrote:

I would use the StringLengthCalculator to calculate the original length of the string.

Then use a StringReplacer to remove all special characters.

Repeat the StringLengthCalculator and use an AttributeCretator to calculate the difference in length.

That will tell you the number of special characters.

Could also be done in one AttributeCreator using string functions like StringLength and ReplaceString in the Text Editor.

yes it working


Here is an alternative that uses only one transformer with a regular expression:

Using a StringSearcher, paste the following Regular Expression to match your cases:

[-\\/].*[-\\/]

 

This will output your required features in the Matched port.


tomjerry.vl
Forum|alt.badge.img
  • Author
  • December 6, 2019
daveatsafe wrote:

Hi @tomjerry.vl,

Please use a StringSearcher with the expression '[/-]' and Advanced - All Matches List Name set to '_matches'. THis will create a list of all the special character matches in the string.

Next, we want to find the features with more than one element in the list, which we can do with a ListElementCounter on the _matches{} list. Use a Tester afterwards to find _element_count > 1.

ok but in fme 2017.1 version ListElementCounter parameters no list attribute available how to resolve this issue please tell me

 


daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • December 6, 2019
tomjerry.vl wrote:

ok but in fme 2017.1 version ListElementCounter parameters no list attribute available how to resolve this issue please tell me

 

Clicking on the triangle beside Advanced in the transformer settings should expose the list entries for you.


tomjerry.vl
Forum|alt.badge.img
  • Author
  • December 11, 2019
francoissimard9 wrote:

Here is an alternative that uses only one transformer with a regular expression:

Using a StringSearcher, paste the following Regular Expression to match your cases:

[-\\/].*[-\\/]

 

This will output your required features in the Matched port.

I have used this expression " @StringLength(@Value(housenumbe))-@StringLength(@ReplaceRegEx(@Value(housenumbe),[-/],,true)) "

then output result is shown below

5-4

3-2

6-4

5-3

9-6

I want total subtraction value

like this

1

1

2

2

3

please tell me sir


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • December 11, 2019
tomjerry.vl wrote:

I have used this expression " @StringLength(@Value(housenumbe))-@StringLength(@ReplaceRegEx(@Value(housenumbe),[-/],,true)) "

then output result is shown below

5-4

3-2

6-4

5-3

9-6

I want total subtraction value

like this

1

1

2

2

3

please tell me sir

To do the math, you will need the @Evaluate() function.


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • December 11, 2019

If an attribute contains the value 5-4 and you need it to be 1, you can use the ExpressionEvaluator transformer to do the math.

Hope this helps.


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