Skip to main content
Released

Fix @StringLength Function

Related products:Transformers

takashi
Evangelist

According to the documentations, the @StringLength function has to be equivalent to the StringLengthCalculator transformer. i.e. it should return the number of characters in the given string.

StringLength(str) Returns the length of the input string. Equivalent transformer: StringLengthCalculator

https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/!Transformer_Parameters/StringFunctions.htm

StringLengthCalculator Usage Notes Note that in non-ASCII character sets, the length is the number of actual characters (some or all of which could be multi-byte) in the string, which may not match the number of bytes used to store the string.

http://docs.safe.com/fme/2019.0/html/FME_Desktop_Documentation/FME_Transformers/Transformers/stringlengthcalculator.htm

However, the function could return wrong number if the given string contains muti-byte characters.

For example, if the given string was '???' with UTF-8 encoding, the number of characters should be 3 and the StringLengthCalculater returns 3 correctly, but the @StringLength function returns 6 on Windows. It seems to return the number of bytes, but the correct number of bytes is 9 for the string with UTF-8. That is, 6 is not either number of characters or number of bytes.

I think the implementation of the function should be fixed so that it exactly complies with the documentations, i.e. always returns the number of characters as well as the StringLengthCalculator.

<strong>This post is closed to further activity.</strong><br /> It may be a question with a best answer, an implemented idea, or just a post needing no comment.<br /> If you have a follow-up or related question, please <a href="https://community.safe.com/topic/new">post a new question or idea</a>.<br /> If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Evangelist
  • Author
  • March 20, 2019

cf. C129765, C143664


takashi
Evangelist
  • Author
  • March 20, 2019

And, if my memory was correct, the @StringLength function in the old versions (FME 2014? and earlier) could always return the actual number of characters correctly even if the given string contains multi-byte characters. I strongly hope that the correct behavior would be restored.


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