Page 1 of 1

Read single character from uni-string

Posted: Wed Sep 25, 2019 5:48 pm
by hbraun
Hello,

I use WinCC-OA 3.16P11.

Is it possible to read a single character from an uni-string. Adressing characters with [index] seems to work byte-wise only.

For example reading the 3. character ("ö") from string "aböcd" does not work with string[2]. Also I could not find any uniStr-function that has this functionality.

Use-case is to make a filter-string from the original string that ignores case with patternMatch(), for example the filter string for "aböcd" would be "[aA][bB][öÖ][cC][dD]".

Is there any way to achieve this?

Kind regards

Re: Read single character from uni-string

Posted: Wed Sep 25, 2019 5:53 pm
by dvribeira
Why not

Code: Select all

substr(your_string_var, 2, 1)
?

From P013 onwards you could also use:

Code: Select all

your_string_var.mid(2, 1);
or

Code: Select all

your_string_var.at(2);
But they will always return a string type, obviously. Not sure if that might be a problem for you.

Re: Read single character from uni-string

Posted: Thu Sep 26, 2019 7:06 am
by hbraun
Thank you, uniSubStr() works fine. When searching for uni-string functions in the help I searched for "uniStr*" so I did not find it...

Re: Read single character from uni-string

Posted: Thu Sep 26, 2019 9:15 am
by dvribeira
Indeed, sorry, uniSubStr instead of substr. The other two introduced with P013 work on the unicode character level and not on bytes, so they would be good for this as well.

Re: Read single character from uni-string

Posted: Tue Oct 01, 2019 8:11 am
by gschijndel
Also the 'strwalk' function should be able to read a single Unicode character.