How to take some Chinese from string?

Kerry Ou 226 Reputation points
2021-03-19T08:22:38.483+00:00

VB code
How to get the Chinese from "Office办公室" this string ?
mystr is variables.
Sample:
mystr="Office办公室"
I want
me.Txt_Dept.Text="办公室"

Thank you.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,404 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,657 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.4K Reputation points
    2021-03-19T08:48:33.203+00:00

    Check a solution that uses Regular Expressions:

    Dim mystr = "Office办公室"
    Dim result = Regex.Replace(mystr, "[^\p{IsCJKUnifiedIdeographs}]+", " ").Trim
    me.Txt_Dept.Text = result
    

    The expression can be improved to keep more kinds of letters.


1 additional answer

Sort by: Most helpful
  1. Castorix31 83,096 Reputation points
    2021-03-19T08:59:51.4+00:00

    For example =>

    Dim sString = "Office办公室"
    Dim sResult As String = RegularExpressions.Regex.Replace(sString, "[\u4E00-\u9FA5]", "")