Solved

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


Badge

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 \\

icon

Best answer by erik_jan 5 December 2019, 18:23

View original

12 replies

Userlevel 1
Badge +10

Are all non special characters numbers?

Userlevel 2
Badge +17

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.

Userlevel 2
Badge +12

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.

Badge

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

Userlevel 2
Badge +12

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.

Badge

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.

Badge

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

 

Userlevel 2
Badge +17

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.

Badge

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

Userlevel 2
Badge +12

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.

Userlevel 2
Badge +12

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.

Reply