How to detect Chinese in a string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lookon

    How to detect Chinese in a string?

    I have a string a(for example, a='¤¤¤åChinese' ), and I want to know
    whether there are some Chinese in the string.

    Can someone tell me how to do it? Thanks!
  • Peter Otten

    #2
    Re: How to detect Chinese in a string?

    lookon wrote:
    I have a string a(for example, a='中文Chines e'), and I want to know
    whether there are some Chinese in the string.
    >
    Can someone tell me how to do it? Thanks!
    See



    Instead of re.findall(...)

    you may use

    if re.search(...):
    print "There are Chinese chars"

    Remember to decode the string with the proper encoding first, e. g.

    a = a.decode("utf-8")

    Peter

    Comment

    • lookon

      #3
      Re: How to detect Chinese in a string?

      Get it. Thanks

      Peter Otten wrote:
      lookon wrote:
      >
      I have a string a(for example, a='¤¤¤åChinese' ), and I want to know
      whether there are some Chinese in the string.

      Can someone tell me how to do it? Thanks!
      >
      See
      >

      >
      Instead of re.findall(...)
      >
      you may use
      >
      if re.search(...):
      print "There are Chinese chars"
      >
      Remember to decode the string with the proper encoding first, e. g.
      >
      a = a.decode("utf-8")
      >
      Peter

      Comment

      Working...