本文整理汇总了C#中System.Text.UnicodeEncoding.GetChars方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetChars方法的具体用法?C# UnicodeEncoding.GetChars怎么用?C# UnicodeEncoding.GetChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UnicodeEncoding
的用法示例。
在下文中一共展示了UnicodeEncoding.GetChars方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
private static EMFFont Process(byte[] RecordData)
{
//put the Data into a stream and use a binary reader to read the data
MemoryStream _ms = null;
BinaryReader _br = null;
try
{
_ms = new MemoryStream(RecordData);
_br = new BinaryReader(_ms);
UInt32 Version = _br.ReadUInt32();
Single EmSize = _br.ReadSingle();
UInt32 SizeUnit = _br.ReadUInt32();
Int32 FontStyleFlags = _br.ReadInt32();
_br.ReadUInt32();
UInt32 NameLength = _br.ReadUInt32();
char[] FontFamily = new char[NameLength];
System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
d.GetChars(_br.ReadBytes((int)NameLength * 2),0,(int)NameLength * 2,FontFamily,0);
Font aFont = new Font(new String(FontFamily), EmSize, (FontStyle)FontStyleFlags, (GraphicsUnit)SizeUnit);
EMFFont ThisFont = new EMFFont();
ThisFont.myFont = aFont;
return ThisFont;
}
finally
{
if (_br != null)
_br.Close();
if (_ms != null)
_ms.Dispose();
}
}
示例2: 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);
int actualValue;
actualValue = uEncoding.GetChars(bytes, 0, 0, desChars, 10);
Assert.Equal(0, actualValue);
}
示例3: TestEncodingDecodingGetBytes1
public void TestEncodingDecodingGetBytes1()
{
//pi and sigma in unicode
string Unicode = "\u03a0\u03a3";
UnicodeEncoding UnicodeEnc = new UnicodeEncoding (); //little-endian
//Encode the unicode string.
byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);
//Decode the bytes to a unicode char array.
char[] UniChars = UnicodeEnc.GetChars (UniBytes);
string Result = new string(UniChars);
Assertion.AssertEquals ("Uni #1", Unicode, Result);
}
示例4: PosTest2
public void PosTest2()
{
int expectedValue = _generator.GetInt16(-55) % 10 + 1;
int actualValue;
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int byteCount = uEncoding.GetBytes(srcChars, 0, expectedValue, bytes, 0);
actualValue = uEncoding.GetChars(bytes, 0, expectedValue * 2, desChars, 0);
Assert.Equal(expectedValue, actualValue);
}
示例5: Process
public List<PageItem> Process(int Flags, byte[] RecordData)
{
MemoryStream _ms = null;
BinaryReader _br = null;
MemoryStream _fs = null;
BinaryReader _fr = null;
try
{
_fs = new MemoryStream(BitConverter.GetBytes(Flags));
_fr = new BinaryReader(_fs);
//Byte 1 will be ObjectID - a font in the object table
byte ObjectID = _fr.ReadByte();
//Byte 2 is the real flags
byte RealFlags = _fr.ReadByte();
// 0 1 2 3 4 5 6 7
// X X X X X X X S
// if S = type of brush - if S then ARGB, else a brush object in object table
_ms = new MemoryStream(RecordData);
_br = new BinaryReader(_ms);
bool BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
Brush b;
if (BrushIsARGB)
{
byte A, R, G, B;
B = _br.ReadByte();
G = _br.ReadByte();
R = _br.ReadByte();
A = _br.ReadByte();
b = new SolidBrush(Color.FromArgb(A, R, G, B));
}
else
{
UInt32 BrushID = _br.ReadUInt32();
EMFBrush EMFb = (EMFBrush)ObjectTable[(byte)BrushID];
b = EMFb.myBrush;
}
UInt32 FormatID = _br.ReadUInt32(); // Index of Optional stringFormatobject in Object Table...
UInt32 StringLength = _br.ReadUInt32();
//bounding of string...
Single recX = _br.ReadSingle();
Single recY = _br.ReadSingle();
Single recWidth = _br.ReadSingle();
Single recHeight = _br.ReadSingle();
//Array of Chars...
char[] StringData = new char[StringLength];
System.Text.UnicodeEncoding d = new System.Text.UnicodeEncoding();
d.GetChars(_br.ReadBytes((int)StringLength * 2), 0, (int)StringLength * 2, StringData, 0);
EMFFont EF = (EMFFont)ObjectTable[(byte)ObjectID];
Font f = EF.myFont;
StringFormat sf;
if (ObjectTable.Contains((byte)FormatID))
{
EMFStringFormat ESF = (EMFStringFormat)ObjectTable[(byte)FormatID];
sf = ESF.myStringFormat;
}
else
{
sf = new StringFormat();
}
DoInstructions(f, sf, b, recX, recY, recWidth, recHeight, new String(StringData));
return items;
}
finally
{
if (_br != null)
_br.Close();
if (_ms != null)
_ms.Dispose();
if (_fr != null)
_fr.Close();
if (_fs != null)
_fs.Dispose();
}
}
示例6: NegTest2
public void NegTest2()
{
Char[] srcChars = GetCharArray(10);
Char[] desChars = new Char[10];
Byte[] bytes = null;
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
Assert.Throws<ArgumentNullException>(() =>
{
actualValue = uEncoding.GetChars(bytes, 0, 0, desChars, 0);
});
}
示例7: NegTest10
public void NegTest10()
{
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);
int actualValue;
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
actualValue = uEncoding.GetChars(bytes, 0, 0, desChars, 11);
});
}
示例8: GetStringW
//
// Returns null if property is not set.
//
protected string GetStringW(
uint dwPropertyId)
{
UnicodeEncoding ue = new UnicodeEncoding();
byte[] rgb;
rgb = GetProperty(dwPropertyId);
if((rgb == null) || (rgb.Length < 2))
return null;
// -2 to remove null term for wide character.
else return new string(ue.GetChars( rgb, 0, rgb.Length - 2 ));
}
示例9: ExtractUTF16
private static char[] ExtractUTF16(byte[] content, bool abortAfterTermination)
{
var data = new List<char>();
if (content.Length > 4)
{
var bomBytes = new byte[2];
Array.Copy(content, 0, bomBytes, 0, 2);
var bigEndianEnabled = false;
//
// See Byte Order Mask (BOM) UTF 16 for details
//
if (bomBytes[0] == 0xFE && bomBytes[1] == 0xFF)
{
bigEndianEnabled = true;
}
var encoder = new UnicodeEncoding(bigEndianEnabled, true);
var inputBytes = new byte[content.Length - 2];
Array.Copy(content, 2, inputBytes, 0, inputBytes.Length);
var chars = encoder.GetChars(inputBytes, 0, inputBytes.Length);
foreach (var curChar in chars)
{
if (abortAfterTermination && curChar == '\u0000')
{
break;
}
data.Add(curChar);
}
}
return data.ToArray();
}
示例10: ExtractUTF16_BigEndian
private static char[] ExtractUTF16_BigEndian(byte[] content, bool abortAfterTermination)
{
var data = new List<char>();
// Create a Big Endian UTF 16 Encoder
var encoder = new UnicodeEncoding(true, true);
var chars = encoder.GetChars(content, 0, content.Length);
foreach (var curChar in chars)
{
if (abortAfterTermination && curChar == '\u0000')
{
break;
}
data.Add(curChar);
}
return data.ToArray();
}
示例11: ZeroLengthArrays
public void ZeroLengthArrays ()
{
UnicodeEncoding encoding = new UnicodeEncoding ();
encoding.GetCharCount (new byte [0]);
encoding.GetChars (new byte [0]);
encoding.GetCharCount (new byte [0], 0, 0);
encoding.GetChars (new byte [0], 0, 0);
encoding.GetChars (new byte [0], 0, 0, new char [0], 0);
encoding.GetByteCount (new char [0]);
encoding.GetBytes (new char [0]);
encoding.GetByteCount (new char [0], 0, 0);
encoding.GetBytes (new char [0], 0, 0);
encoding.GetBytes (new char [0], 0, 0, new byte [0], 0);
encoding.GetByteCount ("");
encoding.GetBytes ("");
}
示例12: TestEncodingDecodingGetBytes2
public void TestEncodingDecodingGetBytes2()
{
//pi and sigma in unicode
string Unicode = "\u03a0\u03a3";
UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); //big-endian
//Encode the unicode string.
byte[] UniBytes = UnicodeEnc.GetBytes (Unicode);
//Decode the bytes to a unicode char array.
char[] UniChars = UnicodeEnc.GetChars (UniBytes);
string Result = new string(UniChars);
Assert.AreEqual (Unicode, Result, "Uni #1");
}
示例13: DecryptPassword
public static string DecryptPassword(string password)
{
UnicodeEncoding ByteConverter = new UnicodeEncoding();
StringBuilder sb = new StringBuilder();
byte[] encryptedPassword = Convert.FromBase64String(password);
sb.Append(ByteConverter.GetChars(ProtectedData.Unprotect(encryptedPassword, SmanConstants.ProtectionKey, DataProtectionScope.CurrentUser)));
return sb.ToString();
}
示例14: btnReplay_Click
private void btnReplay_Click(object sender, RoutedEventArgs e)
{
if (!Directory.Exists("./Replays"))
{
Directory.CreateDirectory("./Replays");
}
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = Directory.GetCurrentDirectory() + "\\Replays";
dlg.DefaultExt = ".sgs"; // Default file extension
dlg.Filter = "Replay File (.sgs)|*.sgs|Crash Report File (.rpt)|*.rpt|All Files (*.*)|*.*"; // Filter files by extension
bool? result = dlg.ShowDialog();
if (result != true) return;
string fileName = dlg.FileName;
Client client;
MainGame game = null;
try
{
client = new Client();
game = new MainGame();
game.OnNavigateBack += game_OnNavigateBack;
Stream stream = File.Open(fileName, FileMode.Open);
byte[] seed = new byte[8];
stream.Seek(-16, SeekOrigin.End);
stream.Read(seed, 0, 8);
if (System.Text.Encoding.Default.GetString(seed).Equals(Misc.MagicAnimal.ToString("X8")))
{
stream.Read(seed, 0, 8);
game.HasSeed = Convert.ToInt32(System.Text.Encoding.Default.GetString(seed), 16);
}
stream.Seek(0, SeekOrigin.Begin);
byte[] bytes = new byte[4];
stream.Read(bytes, 0, 4);
int length = BitConverter.ToInt32(bytes, 0);
if (length != 0)
{
byte[] msg = new byte[length];
stream.Read(msg, 0, length);
UnicodeEncoding uniEncoding = new UnicodeEncoding();
MessageBox.Show(new String(uniEncoding.GetChars(msg)));
}
client.StartReplay(stream);
game.NetworkClient = client;
}
catch (Exception)
{
MessageBox.Show("Failed to open replay file.");
return;
}
if (game != null)
{
MainGame.BackwardNavigationService = this.NavigationService;
game.Start();
// this.NavigationService.Navigate(game);
}
}