How to concatenate multiple unicode string?
24,218
if you want to concatenate two strings use +
>>> '가' + 'ㄱ'
'\xea\xb0\x80\xe3\x84\xb1'
>>> u'가' + u'ㄱ'
u'\uac00\u3131'
>>> print u'가' + u'ㄱ'
가ㄱ
this means you can use
output1 + output2
Author by
user1732445
Updated on November 06, 2020Comments
-
user1732445 over 3 years
I have two unicode string
'가'
and'ㄱ'
and I want to concatenate them to get"가ㄱ"
This is my code:
output1 = unicodeQueue(self.queue) # first unicode result output2 = unicodeQueue(self.bufferQueue) # second unicode result sequence = [output1, output2] print sequence output = ''.join(sequence) return output
And this is the output I'm getting:
[u'\uac00', u'\u3131'] ㄱ가가ㄱ가
I don't know why it doesn't produce correct result, can anyone help me with this?
-
NPE over 11 yearsI am unable to reproduce this.
-
user1732445 over 11 years@NPE I uploaded my partial script, the main of my question is "how to concatenate two unicode in python?"
-
SilentGhost over 11 years@user1732445: there's nothing obviously wrong w/ your code.
-
kennytm over 11 yearsWorks for me. May be try
u''.join(sequence)
. -
user1732445 over 11 years@KennyTM Hmm. Thanks.. at now It works for me...
-
EnricoGiampieri over 11 yearsSame here, nothing wrong with the join, it works as supposed to the unicodeQueue class?
-
-
Perkins over 11 yearsKeep in mind that + works more slowly than
unicode.join(u'',vals)
orstr.join('',vals)
, but if it works when join doesn't, by all means, use it.