How can get substring when the string have both Chinese characters and English characters to meet Oracle requirements?

Description: Description field have much Chinese characters and English characters, in Oracle system, one Chinese characters equal three English characters
Requirement: Get Description substring from first character and substring’s length<240 characters


Is the encoding UTF-8? in UTF-8, Chinese character is usually encoded as 3 bytes but not always. So we need to evaluate actual byte length, I think. Can you try the following expression?

yourString.Substring(0,Enumerable.Range(0,maxLimit).Where(Function(i) System.Text.Encoding.GetEncoding("UTF-8").GetBytes(yourString.Substring(0,i)).Length<maxLimit).Max)

If your encoding is not UTF-8, please modify it to your encoding.


Thank you so much for your help, Your solution perfectly solved my problem! :clap: :clap:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.