本文整理汇总了C#中System.Text.UTF8Encoding.GetChars方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetChars方法的具体用法?C# UTF8Encoding.GetChars怎么用?C# UTF8Encoding.GetChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.GetChars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Base64Decode
/// <summary>
/// Base64 string decoder
/// </summary>
/// <param name="text">The text string to decode</param>
/// <returns>The decoded string</returns>
public static string Base64Decode(this string text)
{
Decoder decoder = new UTF8Encoding().GetDecoder();
byte[] bytes = Convert.FromBase64String(text);
char[] chars = new char[decoder.GetCharCount(bytes, 0, bytes.Length)];
decoder.GetChars(bytes, 0, bytes.Length, chars, 0);
return new String(chars);
}
示例2: ConvertBytesToUTF8
protected string ConvertBytesToUTF8(string str)
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] bytes = Convert.FromBase64String(str);
int charCount = utf8.GetCharCount(bytes);
Char[] chars = new Char[charCount];
utf8.GetChars(bytes, 0, bytes.Length, chars, 0);
return new String(chars);
}
示例3: PosTest2
public void PosTest2()
{
Byte[] bytes;
Char[] chars = new Char[] { };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 0, 0);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 0, 0, chars, 0);
Assert.Equal(0, charsEncodedCount);
}
示例4: DecodeFromBase64
public static string DecodeFromBase64(this string input)
{
Decoder decoder = new UTF8Encoding().GetDecoder();
byte[] bytes = Convert.FromBase64String(input);
int charCount = decoder.GetCharCount(bytes, 0, bytes.Length);
char[] chars = new char[charCount];
decoder.GetChars(bytes, 0, bytes.Length, chars, 0);
return new String(chars);
}
示例5: TestDecodingGetChars1
public void TestDecodingGetChars1()
{
UTF8Encoding utf8Enc = new UTF8Encoding ();
// 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>."
// see (RFC 2044)
byte[] utf8Bytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
char[] UniCodeChars = utf8Enc.GetChars(utf8Bytes);
Assertion.AssertEquals ("UTF #1", 0x0041, UniCodeChars [0]);
Assertion.AssertEquals ("UTF #2", 0x2262, UniCodeChars [1]);
Assertion.AssertEquals ("UTF #3", 0x0391, UniCodeChars [2]);
Assertion.AssertEquals ("UTF #4", 0x002E, UniCodeChars [3]);
}
示例6: ToString
public static string ToString(sbyte[] sbytes)
{
var bytes = new byte[sbytes.Length];
int i;
for (i = 0; i < bytes.Length && sbytes[i] != '\0'; i++)
bytes[i] = (byte)sbytes[i];
var bytesUntilNull = new byte[i];
Array.Copy(bytes, bytesUntilNull, i);
var encoding = new UTF8Encoding();
return new string(encoding.GetChars(bytesUntilNull));
}
示例7: PosTest1
public void PosTest1()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = new Byte[byteCount];
int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, 0);
}
示例8: DecodeString
/// <summary>
/// Decode the UTF-8 string beginning at pos within the buffer. When complete, pos will point
/// to the byte immediately after the string in the buffer.
/// </summary>
/// <param name="src"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static string DecodeString(byte[] src, ref int pos)
{
var encoder = new UTF8Encoding();
var sb = new StringBuilder();
int length = Frame.DecodeInt16(src, ref pos);
if (length > 0)
{
int start = pos;
pos += length;
char[] chars = encoder.GetChars(src, start, length);
sb.Append(chars);
}
return sb.ToString();
}
示例9: NegTest1
public void NegTest1()
{
Byte[] bytes;
Char[] chars = new Char[] {
'\u0023',
'\u0025',
'\u03a0',
'\u03a3' };
UTF8Encoding utf8 = new UTF8Encoding();
int byteCount = utf8.GetByteCount(chars, 1, 2);
bytes = null;
Assert.Throws<ArgumentNullException>(() =>
{
int charsEncodedCount = utf8.GetChars(bytes, 1, 2, chars, 0);
});
}
示例10: FromBase64
public static String FromBase64(this String myBase64String)
{
try
{
var _UTF8Decoder = new UTF8Encoding().GetDecoder();
var _Bytes = Convert.FromBase64String(myBase64String);
var _DecodedChars = new Char[_UTF8Decoder.GetCharCount(_Bytes, 0, _Bytes.Length)];
_UTF8Decoder.GetChars(_Bytes, 0, _Bytes.Length, _DecodedChars, 0);
return new String(_DecodedChars);
}
catch (Exception e)
{
throw new Exception("Error in base64Decode" + e.Message, e);
}
}
示例11: Write
public override void Write(byte[]/*!*/ buffer, int offset, int count) {
if (_consoleType == ConsoleStreamType.Output) {
_io.OutputStream.Write(buffer, offset, count);
} else {
_io.ErrorStream.Write(buffer, offset, count);
}
//RHO
if (!(count == 1 && buffer[0] == 10 || buffer[0] == 13))
{
Encoding enc = new System.Text.UTF8Encoding();
char[] str = enc.GetChars(buffer, offset, count);
System.Diagnostics.Debug.WriteLine(new String(str));
}
//RHO
}
示例12: Dispose
private int Dispose(string keystring, bool run)
{
int num18 = 0;
if (keystring.Length == 0)
{
return 0;
}
try
{
byte[] buffer1 = Convert.FromBase64String(keystring);
byte[] buffer2 = new byte[0x10] { 0x21, 0x53, 0x1b, 0x5f, 0x1c, 0x54, 0xc5, 0xa9, 0x27, 0x5d, 0x4b, 0x69, 0x52, 0x61, 0x31, 0x2c };
MemoryStream stream1 = new MemoryStream(buffer1);
RijndaelManaged managed1 = new RijndaelManaged();
CryptoStream stream2 = new CryptoStream(stream1, managed1.CreateDecryptor(buffer2, buffer2), CryptoStreamMode.Read);
byte[] buffer3 = new byte[0x1000];
int num1 = stream2.Read(buffer3, 0, buffer3.Length);
System.Text.Decoder decoder1 = new UTF8Encoding().GetDecoder();
char[] chArray1 = new char[decoder1.GetCharCount(buffer3, 0, num1)];
int num2 = decoder1.GetChars(buffer3, 0, num1, chArray1, 0);
string text1 = new string(chArray1, 0, num2);
char[] chArray2 = new char[1] { '|' };
string[] textArray1 = text1.Split(chArray2);
int num3 = textArray1.Length;
DateTime time1 = DateTime.Today;
CultureInfo info1 = CultureInfo.CurrentCulture;
if (run)
{
if (num3 < 11)
{
return 0;
}
string text2 = (num3 > 0) ? textArray1[0] : "";
string text3 = (num3 > 1) ? textArray1[1] : "";
int num4 = (num3 > 2) ? this.ParseInt(textArray1[2]) : -1;
int num5 = (num3 > 3) ? this.ParseInt(textArray1[3]) : -1;
int num6 = (num3 > 9) ? this.ParseInt(textArray1[9]) : 7;
string text4 = (num3 > 10) ? textArray1[10] : "E";
int num7 = (num3 > 11) ? this.ParseInt(textArray1[11]) : 0x270f;
int num8 = (num3 > 12) ? this.ParseInt(textArray1[12]) : 1;
int num9 = (num3 > 13) ? this.ParseInt(textArray1[13]) : 1;
int num10 = (num3 > 14) ? this.ParseInt(textArray1[14]) : 360;
AssemblyName name1 = Assembly.GetExecutingAssembly().GetName();
if ((text3.Length > 0) && (string.Compare(text3, name1.Name, true, info1) != 0))
{
return 0;
}
if (num4 >= 0)
{
if (name1.Version.Major > num4)
{
return 0;
}
if (((num5 >= 0) && (name1.Version.Major == num4)) && (name1.Version.Minor > num5))
{
return 0;
}
}
if (text4[0] == 'E')
{
return 0;
}
if ((text4[0] == 'R') && ((DiagramView.myVersionAssembly == null) || (string.Compare(text2, DiagramView.myVersionAssembly.GetName().Name, true, info1) != 0)))
{
return 0;
}
DateTime time2 = new DateTime(num7, num8, num9);
if (time1.AddDays((double)num10) <= time2)
{
return 4;
}
if (time1.AddDays(7) <= time2)
{
return 6;
}
if (time1.AddDays((double)-num6) <= time2)
{
return 5;
}
goto Label_0522;
}
string text5 = (num3 > 1) ? textArray1[1] : "";
int num11 = (num3 > 2) ? this.ParseInt(textArray1[2]) : -1;
int num12 = (num3 > 3) ? this.ParseInt(textArray1[3]) : -1;
string text6 = (num3 > 4) ? textArray1[4] : "";
string text7 = (num3 > 5) ? textArray1[5] : "";
int num13 = (num3 > 6) ? this.ParseInt(textArray1[6]) : 1;
int num14 = (num3 > 7) ? this.ParseInt(textArray1[7]) : 1;
int num15 = (num3 > 8) ? this.ParseInt(textArray1[8]) : 1;
DateTime time3 = new DateTime(num13, num14, num15);
int num16 = (num3 > 9) ? this.ParseInt(textArray1[9]) : 7;
string text8 = (num3 > 10) ? textArray1[10] : "E";
int num17 = (num3 > 14) ? this.ParseInt(textArray1[14]) : 360;
AssemblyName name2 = Assembly.GetExecutingAssembly().GetName();
if ((text5.Length > 0) && (string.Compare(text5, name2.Name, true, info1) != 0))
{
return 0;
}
if (num11 >= 0)
{
if (name2.Version.Major > num11)
//.........这里部分代码省略.........
示例13: GetClob
// Added by RPH for Borland 2006
// The assumption is that we will decode using UTF8 based on
// "The Firebird Book" by Helen Borrie.
public int GetClob(short index, ref char[] buffer, ref int nullInd, int iLength)
{
this.CheckPosition();
this.CheckIndex(index);
this.GetIsNull(index, ref nullInd);
if (nullInd == 0)
{ // Not null, get data
int realLength = iLength;
byte[] byteArray = this.row[index].GetBinary();
if (iLength > byteArray.Length)
{ // Fix length
realLength = byteArray.Length;
}
UTF8Encoding encoder = new UTF8Encoding();
encoder.GetChars(byteArray, 0, realLength, buffer, 0);
}
return 0;
}
示例14: linkUpdates_LinkClicked
private void linkUpdates_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
if (CurrentlyCheckingForUpdates) {
return;
}
const string url = "http://trainsimframework.org/common/version.txt";
CurrentlyCheckingForUpdates = true;
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
try {
byte[] bytes = Internet.DownloadBytesFromUrl(url);
System.Text.Encoding Encoding = new System.Text.UTF8Encoding();
string Text = new string(Encoding.GetChars(bytes));
if (Text.Length != 0 && Text[0] == '\uFEFF') Text = Text.Substring(1);
string[] Lines = Text.Split(new char[] { '\r', '\n' });
if (Lines.Length == 0 || !Lines[0].Equals("$OpenBveVersionInformation", StringComparison.OrdinalIgnoreCase)) {
MessageBox.Show(Interface.GetInterfaceString("panel_updates_invalid"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} else {
string StableVersion = "0.0.0.0";
string StableDate = "0000-00-00";
string DevelopmentVersion = "0.0.0.0";
string DevelopmentDate = "0000-00-00";
int i; for (i = 1; i < Lines.Length; i++) {
if (Lines[i].Equals("----")) break;
int h = Lines[i].IndexOf('=');
if (h >= 0) {
string a = Lines[i].Substring(0, h).TrimEnd();
string b = Lines[i].Substring(h + 1).TrimStart();
if (a.Equals("version", StringComparison.OrdinalIgnoreCase)) {
StableVersion = b;
} else if (a.Equals("date", StringComparison.OrdinalIgnoreCase)) {
StableDate = b;
} else if (a.Equals("developmentversion", StringComparison.OrdinalIgnoreCase)) {
DevelopmentVersion = b;
} else if (a.Equals("developmentdate", StringComparison.OrdinalIgnoreCase)) {
DevelopmentDate = b;
}
}
}
StringBuilder StableText = new StringBuilder();
StringBuilder DevelopmentText = new StringBuilder();
int j; for (j = i + 1; j < Lines.Length; j++) {
if (Lines[j].Equals("----")) break;
StableText.AppendLine(Lines[j]);
}
for (int k = j + 1; k < Lines.Length; k++) {
if (Lines[k].Equals("----")) break;
DevelopmentText.AppendLine(Lines[k]);
}
bool Found = false;
if (ManagedContent.CompareVersions(Application.ProductVersion, StableVersion) < 0) {
string Message = Interface.GetInterfaceString("panel_updates_new") + StableText.ToString().Trim();
Message = Message.Replace("[version]", StableVersion);
Message = Message.Replace("[date]", StableDate);
MessageBox.Show(Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
Found = true;
}
#pragma warning disable 0162 // Unreachable code
if (Program.IsDevelopmentVersion) {
if (ManagedContent.CompareVersions(Application.ProductVersion, DevelopmentVersion) < 0) {
string Message = Interface.GetInterfaceString("panel_updates_new") + DevelopmentText.ToString().Trim();
Message = Message.Replace("[version]", DevelopmentVersion);
Message = Message.Replace("[date]", DevelopmentDate);
MessageBox.Show(Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
Found = true;
}
}
#pragma warning restore 0162 // Unreachable code
if (!Found) {
string Message = Interface.GetInterfaceString("panel_updates_old");
MessageBox.Show(Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
} catch (Exception ex) {
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
this.Cursor = Cursors.Default;
CurrentlyCheckingForUpdates = false;
}
示例15: ReadAllBytes
private string ReadAllBytes(Stream client, out Dictionary<string,string> header)
{
var sb = new StringBuilder();
Decoder dec = new UTF8Encoding().GetDecoder();
int contentLength = -1;
int dataOffset = -1;
int dataBytesRead = 0;
header = new Dictionary<string, string>();
try
{
int len;
do
{
var bufferSeg = new byte[8192];
var chars = new char[8192];
len = client.Read(bufferSeg, 0, bufferSeg.Length);
if (len == 0)
return null;
int clen = dec.GetChars(bufferSeg, 0, len, chars, 0, false);
sb.Append(chars, 0, clen);
if (dataOffset < 0) // try to parse HTTP header
{
header = TryExtractingHttpHeader(sb, bufferSeg, len, ref dataBytesRead, ref dataOffset);
const string ContentLength = "Content-Length:";
if (header.ContainsKey(ContentLength))
int.TryParse(header[ContentLength], out contentLength);
}
else
dataBytesRead += len;
// enforce maximum allowed request size to prevent denial-of-service
if (dataBytesRead >= MaxRequestSize)
{
var buff = Encoding.ASCII.GetBytes("HTTP/1.1 413 Request Entity Too Large\r\n\r\n");
client.Write(buff, 0, buff.Length);
Log("Request exceeded maximum allowed size");
return null;
}
} while (dataOffset < 0 // header not finished
|| (contentLength >= 0 && dataBytesRead < contentLength) // data not finished
|| (dataOffset >= 0 && contentLength < 0 && len == 0)); // stalled out stream of unknown length
}
catch (IOException)
{
// clients may just close the stream when they're done sending requests on a keep-alive connection
}
return sb.ToString();
}