Changeset 2541


Ignore:
Timestamp:
Nov 21, 2016 1:47:57 PM (5 years ago)
Author:
toby
Message:

New Unicode stripper (G2G.StripUnicode?)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrls.py

    r2531 r2541  
    34053405        msg1 = msg.replace('\n ','\n')
    34063406    return msg.replace('\n\t','\n')
     3407
     3408def StripUnicode(string,subs='.'):
     3409    '''Strip non-ASCII characters from strings
     3410   
     3411    :param str string: string to strip Unicode characters from
     3412    :param str subs: character(s) to place into string in place of each
     3413      Unicode character. Defaults to '.'
     3414
     3415    :returns: a new string with only ASCII characters
     3416    '''
     3417    s = ''
     3418    for c in string:
     3419        if ord(c) < 128:
     3420            s += c
     3421        else:
     3422            s += subs
     3423    return s.encode('ascii','replace')
    34073424       
    34083425################################################################################
Note: See TracChangeset for help on using the changeset viewer.