Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created May 14, 2009 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/111719 to your computer and use it in GitHub Desktop.
Save metaskills/111719 to your computer and use it in GitHub Desktop.
# Ruby: 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9]
# Using a both types of encoded string literals
>> ud1 = "\344\270\200\344\272\21434\344\272\224\345\205\255"
=> "\xE4\xB8\x80\xE4\xBA\x8C34\xE4\xBA\x94\xE5\x85\xAD"
>> d1 = SqlServerUnicode.create!(:nvarchar => ud1)
=> #<SqlServerUnicode id: 12, nchar: nil, nvarchar: "一二34五六", ntext: nil, ntext_10: nil, nchar_10: nil, nvarchar_100: nil>
>> d1.reload.nvarchar
=> "一二34五六"
>>
?> ud2 = "\344\270\200\344\272\21434\344\272\224\345\205\255".force_encoding('UTF-8')
=> "一二34五六"
>> d2 = SqlServerUnicode.create!(:nvarchar => ud2)
=> #<SqlServerUnicode id: 13, nchar: nil, nvarchar: "一二34五六", ntext: nil, ntext_10: nil, nchar_10: nil, nvarchar_100: nil>
>> d2.reload.nvarchar
=> "一二34五六"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment