text_plain_output_1.png
import tensorflow as tf

tf.constant(u'Thanks 😊')

tf.constant([u"You're", u'welcome!']).shape

text_utf8 = tf.constant(u'语言处理')
text_utf8

text_utf16be = tf.constant(u'语言处理'.encode('UTF-16-BE'))
text_utf16be

text_chars = tf.constant([ord(char) for char in u'语言处理'])
text_chars

tf.strings.unicode_decode(text_utf8, input_encoding='UTF-8')

tf.strings.unicode_encode(text_chars, output_encoding='UTF-8')

tf.strings.unicode_transcode(text_utf8, input_encoding='UTF8', output_encoding='UTF-16-BE')

batch_utf8 = [s.encode('UTF-8') for s in [u'hÃllo', u'What is the weather tomorrow', u'Göödnight', u'😊']]
batch_chars_ragged = tf.strings.unicode_decode(batch_utf8, input_encoding='UTF-8')

batch_chars_padded = batch_chars_ragged.to_tensor(default_value=-1)

batch_chars_sparse = batch_chars_ragged.to_sparse()
nrows, ncols = batch_chars_sparse.dense_shape.numpy()
elements = [['_' for i in range(ncols)] for j in range(nrows)]
for (row, col), value in zip(batch_chars_sparse.indices.numpy(), batch_chars_sparse.values.numpy()):
    elements[row][col] = str(value)
value_lengths = []
for row in elements:
    for value in row:
        value_lengths.append(len(value))
max_width = max(value_lengths)

tf.strings.unicode_encode([[99, 97, 116], [100, 111, 103], [99, 111, 119]], output_encoding='UTF-8')

tf.strings.unicode_encode(batch_chars_ragged, output_encoding='UTF-8')

tf.strings.unicode_encode(tf.RaggedTensor.from_sparse(batch_chars_sparse), output_encoding='UTF-8')

tf.strings.unicode_encode(tf.RaggedTensor.from_tensor(batch_chars_padded, padding=-1), output_encoding='UTF-8')

thanks = u'Thanks 😊'.encode('UTF-8')
num_bytes = tf.strings.length(thanks).numpy()
num_chars = tf.strings.length(thanks, unit='UTF8_CHAR').numpy()

tf.strings.substr(thanks, pos=7, len=1).numpy()