本文整理汇总了C#中UnicodeEncoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetString方法的具体用法?C# UnicodeEncoding.GetString怎么用?C# UnicodeEncoding.GetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnicodeEncoding
的用法示例。
在下文中一共展示了UnicodeEncoding.GetString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetFromByteArray
public void SetFromByteArray(byte[] bytes, bool metaOnly = false)
{
UnicodeEncoding encoding = new UnicodeEncoding();
int arIndex = 0;
Index = KLFCommon.BytesToInt(bytes, arIndex);
arIndex += 4;
int StringSize = KLFCommon.BytesToInt(bytes, arIndex);
arIndex += 4;
Player = encoding.GetString(bytes, arIndex, StringSize);
arIndex += StringSize;
StringSize = KLFCommon.BytesToInt(bytes, arIndex);
arIndex += 4;
Description = encoding.GetString(bytes, arIndex, StringSize);
arIndex += StringSize;
Image = new byte[bytes.Length-arIndex];
Array.Copy(bytes, arIndex, Image, 0, Image.Length);
}
示例2: setFromByteArray
public void setFromByteArray(byte[] bytes, bool meta_only = false) {
UnicodeEncoding encoding = new UnicodeEncoding();
int array_index = 0;
index = KLFCommon.intFromBytes(bytes, array_index);
array_index += 4;
int string_size = KLFCommon.intFromBytes(bytes, array_index);
array_index += 4;
player = encoding.GetString(bytes, array_index, string_size);
array_index += string_size;
string_size = KLFCommon.intFromBytes(bytes, array_index);
array_index += 4;
description = encoding.GetString(bytes, array_index, string_size);
array_index += string_size;
image = new byte[bytes.Length-array_index];
Array.Copy(bytes, array_index, image, 0, image.Length);
}
示例3: PosTest3
public void PosTest3()
{
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
String expectedValue = "";
String actualValue;
actualValue = uEncoding.GetString(bytes, 0, 0);
Assert.Equal(expectedValue, actualValue);
}
示例4: PosTest1
public void PosTest1()
{
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
bool expectedValue = true;
bool actualValue = true;
String desString = uEncoding.GetString(bytes, 0, 20);
desChars = desString.ToCharArray();
for (int i = 0; i < 10; i++)
{
actualValue = actualValue & (desChars[i] == srcChars[i]);
}
Assert.Equal(expectedValue, actualValue);
}
示例5: EncodingUTF8
public static string EncodingUTF8(string str ) {
/*Encoding srcEncodingFormat = Encoding.Unicode;
Encoding dstEncodingFormat = Encoding.UTF8;
byte[] originalByteString = srcEncodingFormat.GetBytes(str);
byte[] convertedByteString = Encoding.Convert(srcEncodingFormat, dstEncodingFormat, originalByteString);
return dstEncodingFormat.GetString(convertedByteString);
*/
//return System.Text.RegularExpressions.Regex.Replace(str, @"\sFigure \d+.\d+\s", " Figure 1 ");
UnicodeEncoding unicode = new UnicodeEncoding();
// Encode the string.
Byte[] encodedBytes = unicode.GetBytes(str);
// Decode bytes back to string.
// Notice Pi and Sigma characters are still present.
String decodedString = unicode.GetString(encodedBytes);
return decodedString;
}
示例6: Main
//Asymetric
void Main()
{
try
{
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
byte[] encryptedData;
byte[] decryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(false));
decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(true));
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
}
catch (ArgumentNullException)
{
Console.WriteLine("Encryption failed.");
}
}
示例7: handleInteropMessage
protected void handleInteropMessage(KLFCommon.PluginInteropMessageID id, byte[] data)
{
switch (id)
{
case KLFCommon.PluginInteropMessageID.CHAT_SEND:
if (data != null)
{
String line = encoder.GetString(data);
InTextMessage message = new InTextMessage();
message.fromServer = false;
message.message = "[" + clientSettings.username + "] " + line;
enqueueTextMessage(message, false);
handleChatInput(line);
}
break;
case KLFCommon.PluginInteropMessageID.PLUGIN_DATA:
String new_watch_player_name = String.Empty;
if (data != null && data.Length >= 9)
{
UnicodeEncoding encoder = new UnicodeEncoding();
int index = 0;
//Read current activity status
bool in_flight = data[index] != 0;
index++;
//Read current game title
int current_game_title_length = KLFCommon.intFromBytes(data, index);
index += 4;
currentGameTitle = encoder.GetString(data, index, current_game_title_length);
index += current_game_title_length;
//Send the activity status to the server
if (in_flight)
sendMessageTCP(KLFCommon.ClientMessageID.ACTIVITY_UPDATE_IN_FLIGHT, null);
else
sendMessageTCP(KLFCommon.ClientMessageID.ACTIVITY_UPDATE_IN_GAME, null);
}
break;
case KLFCommon.PluginInteropMessageID.PRIMARY_PLUGIN_UPDATE:
sendPluginUpdate(data, true);
break;
case KLFCommon.PluginInteropMessageID.SECONDARY_PLUGIN_UPDATE:
sendPluginUpdate(data, false);
break;
case KLFCommon.PluginInteropMessageID.SCREENSHOT_SHARE:
if (data != null)
{
lock (screenshotOutLock)
{
queuedOutScreenshot = data;
}
}
break;
case KLFCommon.PluginInteropMessageID.SCREENSHOT_WATCH_UPDATE:
if (data != null && data.Length >= 8)
{
int index = KLFCommon.intFromBytes(data, 0);
int current_index = KLFCommon.intFromBytes(data, 4);
String name = encoder.GetString(data, 8, data.Length - 8);
if (watchPlayerName != name || watchPlayerIndex != index)
{
watchPlayerName = name;
watchPlayerIndex = index;
//Look in the screenshot cache for the requested screenshot
Screenshot cached = getCachedScreenshot(watchPlayerIndex, watchPlayerName);
if (cached != null)
sendClientInteropMessage(KLFCommon.ClientInteropMessageID.SCREENSHOT_RECEIVE, cached.toByteArray());
sendScreenshotWatchPlayerMessage((cached == null), current_index, watchPlayerIndex, watchPlayerName);
}
}
break;
}
}
示例8: GetPropertyValues
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
{
SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();
// Do nothing if there are no properties to retrieve
if (properties.Count == 0)
return settings;
// For properties lacking an explicit SerializeAs setting, set
// SerializeAs to String for strings and primitives, and XML
// for everything else
foreach (SettingsProperty property in properties)
{
if (property.SerializeAs == SettingsSerializeAs.ProviderSpecific)
{
if (property.PropertyType.IsPrimitive || property.PropertyType == typeof(String))
{
property.SerializeAs = SettingsSerializeAs.String;
}
else
{
property.SerializeAs = SettingsSerializeAs.Xml;
}
}
settings.Add(new SettingsPropertyValue(property));
}
// Get the user name or anonymous user ID
string username = (string) context["UserName"];
// NOTE: Consider validating the user name here to prevent
// malicious user names such as "../Foo" from targeting
// directories other than Profile_Data
// Load the profile
if (!String.IsNullOrEmpty(username))
{
StreamReader reader = null;
string[] names;
string values;
byte[] buf = null;
try
{
// Open the file containing the profile data
try
{
string path = string.Format(ProfilePathFormatString, username.Replace('\\', '_'));
reader = new StreamReader(path);
}
catch (IOException)
{
// Not an error if file doesn't exist
return settings;
}
// Read names, values, and buf from the file
names = reader.ReadLine().Split(':');
values = reader.ReadLine();
if (!string.IsNullOrEmpty(values))
{
UnicodeEncoding encoding = new UnicodeEncoding();
values = encoding.GetString
(Convert.FromBase64String(values));
}
string temp = reader.ReadLine();
if (!String.IsNullOrEmpty(temp))
{
buf = Convert.FromBase64String(temp);
}
else
buf = new byte[0];
}
finally
{
if (reader != null)
reader.Close();
}
// Decode names, values, and buf and initialize the
// SettingsPropertyValueCollection returned to the caller
DecodeProfileData(names, values, buf, settings);
}
return settings;
}
示例9: PosTest1
public bool PosTest1()
{
bool retVal = true;
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
bool expectedValue = true;
bool actualValue = true;
TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method");
try
{
String desString = uEncoding.GetString(bytes, 0, 20);
desChars = desString.ToCharArray();
for (int i = 0; i < 10; i++)
{
actualValue = actualValue & (desChars[i] == srcChars[i]);
}
if (expectedValue != actualValue)
{
TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")" + " when chars is :" + ToString(srcChars));
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e + " when chars is :" + ToString(srcChars));
retVal = false;
}
return retVal;
}
示例10: NegTest5
public bool NegTest5()
{
bool retVal = true;
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
String actualValue;
TestLibrary.TestFramework.BeginScenario("NegTest5:Invoke the method and set byteCount out of range.");
try
{
actualValue = uEncoding.GetString(bytes, 0, 21);
TestLibrary.TestFramework.LogError("015", "No ArgumentOutOfRangeException throw out expected.");
retVal = false;
}
catch (ArgumentOutOfRangeException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("016", "Unexpected exception:" + e);
retVal = false;
}
return retVal;
}
示例11: PosTest4
public bool PosTest4()
{
bool retVal = true;
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
String expectedValue = "";
String actualValue;
TestLibrary.TestFramework.BeginScenario("PosTest4:Invoke the method and set byteIndex out of range.");
try
{
actualValue = uEncoding.GetString(bytes, 20, 0);
if (expectedValue != actualValue)
{
TestLibrary.TestFramework.LogError("017", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")" + " when chars is :" + ToString(srcChars));
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("018", "Unexpected exception:" + e);
retVal = false;
}
return retVal;
}
示例12: NegTest1
public void NegTest1()
{
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
String actualValue;
Assert.Throws<ArgumentNullException>(() =>
{
actualValue = uEncoding.GetString(null, 0, 0);
});
}