本文整理汇总了C#中System.Text.ASCIIEncoding.GetChars方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.GetChars方法的具体用法?C# ASCIIEncoding.GetChars怎么用?C# ASCIIEncoding.GetChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.ASCIIEncoding
的用法示例。
在下文中一共展示了ASCIIEncoding.GetChars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFile
public string GetFile(string filename)
{
byte[] rxBuf = new byte[516];
int rxCount;
string s = "";
short blockNumber;
ASCIIEncoding ae = new ASCIIEncoding();
sendTftpPacket(Client.OP_CODE.RRQ, filename, null,-1);//send RRQ
do
{
rxCount = recvTftpPacket(ref rxBuf);
OP_CODE op = (OP_CODE)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(rxBuf, 0));
blockNumber = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(rxBuf, 2));
s += new string(ae.GetChars(rxBuf, sizeof(short) * 2, rxCount - 4 >= 4 ? rxCount - 4 : 0)); ;
sendTftpPacket(Client.OP_CODE.ACK, string.Empty, null, blockNumber);
} while (rxCount >= 516);
//sendTftpPacket(Client.OP_CODE.ACK, string.Empty, null, blockNumber);//final ACK
return s;
}
示例2: WaitForPacket
/// <summary>
/// Wait for a packet. Timeout if necessary.
/// </summary>
public void WaitForPacket()
{
var line = new StringBuilder();
var buffer = new byte[1024];
var charBuffer = new char[1024];
var actualSize = 0;
// if there was an error, nothing to wait for.
if( this._indicatorState == IndicatorState.Error )
{
return;
}
// attempt to get a packet
try
{
actualSize = _sock.Receive(buffer);
}
catch(SocketException ex)
{
PerformError("Socket Error: " + ex.Message);
return;
}
// If we got a packet, then process it.
if( actualSize>0 ) {
// packets are in ASCII
ASCIIEncoding ascii = new ASCIIEncoding();
ascii.GetChars(buffer,0,actualSize,charBuffer,0);
// Break up the packets, they are ASCII lines.
for(int i=0;i<actualSize;i++)
{
char ch = (char)charBuffer[i];
if( ch!='\n' && ch!='\r' )
{
line.Append(ch);
}
else
{
if( line.Length>0 )
{
GotPacket(line.ToString());
line.Length = 0;
}
}
}
}
}
示例3: Environment
//.........这里部分代码省略.........
case Threading.Funneled:
requiredThreadLevel = Unsafe.MPI_THREAD_FUNNELED;
break;
case Threading.Serialized:
requiredThreadLevel = Unsafe.MPI_THREAD_SERIALIZED;
break;
case Threading.Multiple:
requiredThreadLevel = Unsafe.MPI_THREAD_MULTIPLE;
break;
}
if (args == null)
{
unsafe
{
int argc = 0;
byte** argv = null;
Unsafe.MPI_Init_thread(ref argc, ref argv, requiredThreadLevel, out providedThreadLevel);
}
}
else
{
ASCIIEncoding ascii = new ASCIIEncoding();
unsafe
{
// Copy args into C-style argc/argv
int my_argc = args.Length;
byte** my_argv = stackalloc byte*[my_argc];
for (int argidx = 0; argidx < my_argc; ++argidx)
{
// Copy argument into a byte array (C-style characters)
char[] arg = args[argidx].ToCharArray();
fixed (char* argp = arg)
{
int length = ascii.GetByteCount(arg);
byte* c_arg = stackalloc byte[length];
if (length > 0)
{
ascii.GetBytes(argp, arg.Length, c_arg, length);
}
my_argv[argidx] = c_arg;
}
}
// Initialize MPI
int mpi_argc = my_argc;
byte** mpi_argv = my_argv;
Unsafe.MPI_Init_thread(ref mpi_argc, ref mpi_argv, requiredThreadLevel, out providedThreadLevel);
// \todo Copy c-style argc/argv back into args
if (mpi_argc != my_argc || mpi_argv != my_argv)
{
args = new string[mpi_argc];
for (int argidx = 0; argidx < args.Length; ++argidx)
{
// Find the end of the string
int byteCount = 0;
while (mpi_argv[argidx][byteCount] != 0)
++byteCount;
// Determine how many Unicode characters we need
int charCount = ascii.GetCharCount(mpi_argv[argidx], byteCount);
// Convert ASCII characters into unicode characters
char[] chars = new char[charCount];
fixed (char* argp = chars)
{
ascii.GetChars(mpi_argv[argidx], byteCount, argp, charCount);
}
// Create the resulting string
args[argidx] = new string(chars);
}
}
}
}
switch (providedThreadLevel)
{
case Unsafe.MPI_THREAD_SINGLE:
Environment.providedThreadLevel = Threading.Single;
break;
case Unsafe.MPI_THREAD_FUNNELED:
Environment.providedThreadLevel = Threading.Funneled;
break;
case Unsafe.MPI_THREAD_SERIALIZED:
Environment.providedThreadLevel = Threading.Serialized;
break;
case Unsafe.MPI_THREAD_MULTIPLE:
Environment.providedThreadLevel = Threading.Multiple;
break;
default:
throw new ApplicationException("MPI.NET: Underlying MPI library returned incorrect value for thread level");
}
// Setup communicators
Communicator.world = Intracommunicator.Adopt(Unsafe.MPI_COMM_WORLD);
Communicator.self = Intracommunicator.Adopt(Unsafe.MPI_COMM_SELF);
}
}
示例4: ASCIICon
public ASCIICon(byte[] array)
{
ASCIIEncoding encoding = new ASCIIEncoding();
multiString = encoding.GetChars(array);
}
示例5: Main
static void Main(string[] args)
{
#region 测试注释
//var barr= new byte[] { 0x00, 0x8D };
//char c = '1';
//string str = "1";
////List<byte> list = new List<byte>();
////foreach (var item in "李".ToCharArray())
////{
//// var b = System.Convert.ToString(item, 16);
//// list.Add(Tool.GetEncoding().GetBytes(b));
////}
//var buff= Tool.GetEncoding().GetBytes("李俊");
//var bitstr = BitConverter.ToString(buff).Split('-').Select(s => s).ToArray();
//var get= Tool.GetEncoding().GetBytes("133");
//Console.Read();
byte[] list = new byte[]{
0xd6, 0xd0, 0xb9,
0xfa,0xb9, 0xa4,0xc9,0xcc, 0xd2,0xf8,0xd0,
0xd0,0xc4,0xb5,0xb5,0xa4,0xbf,0xa8,0x20
,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20
,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20
,0x20,0x20,0x20,0x20,0x20
};
var e = Encoding.GetEncoding("GBK").GetString(list);
Console.WriteLine(e);
string name = "中国工商银行牡丹卡";
var en = Encoding.GetEncoding("GBK").GetBytes(name);
//把ASCII码转化为对应的字符
ASCIIEncoding AE2 = new ASCIIEncoding();
byte[] ByteArray2 = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 };
char[] CharArray = AE2.GetChars(ByteArray2);
for (int x = 0; x <= CharArray.Length - 1; x++)
{
Console.Write(CharArray[x]);
}
var u = Encoding.ASCII.GetBytes(name);
var str = Tool.GetEncoding().GetChars(list);
//RequestData data = new RequestData();
//var v = DataEntityAttributeHelper.GetDataLength<ResponseData>(p => p.TPDU);
#endregion
using (AsyncSocketService asyncSocketService = new AsyncSocketService(int.Parse(ConfigurationManager.AppSettings["port"])))
{
}
//TcpListenerSocketService tcpListen = new TcpListenerSocketService();
#region MyRegion
//TcpListener tcpListenerServer = new TcpListener(IPAddress.Any, 12345);
//tcpListenerServer.Start();
//Console.WriteLine("等待连接");
//TcpClient tcpClient = tcpListenerServer.AcceptTcpClient();
//while (true)
//{
// Console.WriteLine("连接成功");
// try
// {
// byte[] data = new byte[1024];
// int bytes = tcpClient.Client.Receive(data, data.Length, 0);
// string recStr = Encoding.ASCII.GetString(data, 0, bytes);
// Console.WriteLine(recStr);
// string sendStr = "";
// byte[] sendBytes = Encoding.ASCII.GetBytes(sendStr);
// tcpClient.Client.Send(sendBytes);
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// tcpClient.Close();
// Console.WriteLine("等待连接");
// tcpClient = tcpListenerServer.AcceptTcpClient();
// }
//}
#endregion
}
示例6: NextTokenAny
private TokenType NextTokenAny()
{
TokenType nextTokenType = TokenType.Eof;
char[] chars = new char[1];
_currentToken="";
_currentTokenType = TokenType.Eof;
int finished = _reader.Read(chars,0,1);
bool isNumber=false;
bool isWord=false;
byte[] ba=null;
#if SILVERLIGHT
Encoding AE = System.Text.Encoding.Unicode;
#else
ASCIIEncoding AE = new ASCIIEncoding();
#endif
char[] ascii=null;
Char currentCharacter;
Char nextCharacter;
while (finished != 0 )
{
// convert int to char
ba = new Byte[]{(byte)_reader.Peek()};
ascii = AE.GetChars(ba);
currentCharacter = chars[0];
nextCharacter = ascii[0];
_currentTokenType = GetType(currentCharacter);
nextTokenType = GetType(nextCharacter);
// handling of words with _
if (isWord && currentCharacter=='_')
{
_currentTokenType= TokenType.Word;
}
// handing of words ending in numbers
if (isWord && _currentTokenType==TokenType.Number)
{
_currentTokenType= TokenType.Word;
}
if (_currentTokenType==TokenType.Word && nextCharacter=='_')
{
//enable words with _ inbetween
nextTokenType = TokenType.Word;
isWord=true;
}
if (_currentTokenType==TokenType.Word && nextTokenType==TokenType.Number)
{
//enable words ending with numbers
nextTokenType = TokenType.Word;
isWord=true;
}
// handle negative numbers
if (currentCharacter=='-' && nextTokenType==TokenType.Number && isNumber ==false)
{
_currentTokenType= TokenType.Number;
nextTokenType = TokenType.Number;
//isNumber = true;
}
// this handles numbers with a decimal point
if (isNumber && nextTokenType == TokenType.Number && currentCharacter=='.' )
{
_currentTokenType = TokenType.Number;
}
if (_currentTokenType == TokenType.Number && nextCharacter=='.' && isNumber ==false)
{
nextTokenType = TokenType.Number;
isNumber = true;
}
_colNumber++;
if (_currentTokenType==TokenType.Eol)
{
_lineNumber++;
_colNumber=1;
}
_currentToken = _currentToken + currentCharacter;
//if (_currentTokenType==TokenType.Word && nextCharacter=='_')
//{
// enable words with _ inbetween
// finished = _reader.Read(chars,0,1);
//}
if (_currentTokenType!=nextTokenType)
{
finished = 0;
}
else if (_currentTokenType==TokenType.Symbol && currentCharacter!='-')
{
finished = 0;
}
else
{
finished = _reader.Read(chars,0,1);
}
}
//.........这里部分代码省略.........
示例7: GenerateChar
//随即产生一个字母
char GenerateChar()
{
Byte[] bytes = new Byte[1];
Char[] chars = new Char[1];
ASCIIEncoding ascii = new ASCIIEncoding();
//产生一个从字母a到字母z中间的任何一个字符
bytes[0] = (Byte)(randomNumberGenerator.Next(97,123));
ascii.GetChars(bytes, 0, 1, chars, 0);
return chars[0];
}
示例8: TestIdsIncludingNonAscii
public void TestIdsIncludingNonAscii() {
string id = "myAdderId" + '\u0765' + "1" + @"\uA";
string expectedMarshalledId = @"myAdderId\u07651\\uA";
Adder adder = m_testService.CreateNewWithUserID(id);
string marshalUrl = RemotingServices.GetObjectUri(adder);
Ior adderIor = new Ior(marshalUrl);
IInternetIiopProfile prof = adderIor.FindInternetIiopProfile();
byte[] objectKey = prof.ObjectKey;
ASCIIEncoding enc = new ASCIIEncoding();
string marshalUri = new String(enc.GetChars(objectKey));
Assert.AreEqual(expectedMarshalledId, marshalUri, "wrong user id");
// check if callable
int arg1 = 1;
int arg2 = 2;
Assert.AreEqual(arg1 + arg2, adder.Add(arg1, arg2), "wrong adder result");
}
示例9: NegTest5
public void NegTest5()
{
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] bytes = null;
Assert.Throws<ArgumentNullException>(() =>
{
ascii.GetChars(bytes, 0, 0, new char[0], 0);
});
}
示例10: processGcPage
private static bool processGcPage(string url, byte[] dataDownloaded)
{
bool ret = false;
int lineno = 0;
string line;
int state = 0;
string lineToSearch = "<span id=\"CacheName\">";
int pos;
string cacheName = "";
ASCIIEncoding enc = new ASCIIEncoding();
string pageText = new String(enc.GetChars(dataDownloaded));
CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time.
StringReader stream = new StringReader(pageText);
try
{
while((line = stream.ReadLine()) != null && state < 99)
{
lineno++;
switch(state)
{
case 0:
if((pos = line.IndexOf(lineToSearch)) != -1)
{
pos += lineToSearch.Length;
int pos1 = line.IndexOf("</span>", pos);
if(pos1 > pos)
{
cacheName = line.Substring(pos, pos1-pos).Trim();
LibSys.StatusBar.Trace("OK: cacheName='" + cacheName + "'");
state = 1;
lineToSearch = "<span id=\"LatLon\"";
}
}
break;
case 1:
if((pos = line.IndexOf(lineToSearch)) != -1)
{
pos += lineToSearch.Length;
int pos1 = line.IndexOf("</span>", pos);
if(pos1 > pos)
{
string sCacheCoords = line.Substring(pos, pos1-pos).Trim();
LibSys.StatusBar.Trace("OK: cacheCoords='" + sCacheCoords + "'");
GeoCoord loc = getCleanLocation(sCacheCoords);
//LibSys.StatusBar.Trace("OK: loc='" + loc + "'");
createInfo.init("wpt");
createInfo.lat = loc.Lat;
createInfo.lng = loc.Lng;
createInfo.typeExtra = "geocache";
createInfo.source = url;
createInfo.name = cacheName;
createInfo.url = url;
WaypointsCache.insertWaypoint(createInfo);
WaypointsCache.isDirty = true;
ret = true; // report successfully parsed page
state = 99;
lineToSearch = "";
}
}
break;
}
}
}
catch {}
return ret;
}
示例11: DecryptFromByteArray
/// <summary>
/// Decrypt the encryption stored in this byte array.
/// </summary>
/// <param name="encryptedBytes">The byte array to decrypt.</param>
/// <param name="password">The password to use when decrypting.</param>
/// <returns></returns>
/// <remarks></remarks>
public static String DecryptFromByteArray(this Byte[] encryptedBytes, String password)
{
var decryptedBytes = CryptBytes(password, encryptedBytes, false);
var asciiEncoder = new ASCIIEncoding();
return new String(asciiEncoder.GetChars(decryptedBytes));
}
示例12: ReadHeader
private void ReadHeader(BinaryReader r)
{
byte[] header = r.ReadBytes(10);
ASCIIEncoding e = new ASCIIEncoding();
byte[] desiredHeader = e.GetBytes("MS3D000000");
Int32 version = r.ReadInt32();
if (!thisShouldExistAlready(header, desiredHeader))
{
Console.WriteLine(e.GetChars(header));
Console.WriteLine(e.GetChars(desiredHeader));
Error("Unknown data type!");
}
if (version != 4)
{
Error("Bad MS3D version! Use version 4.");
}
}
示例13: NextTokenAny
private Topology.Converters.WellKnownText.TokenType NextTokenAny()
{
Topology.Converters.WellKnownText.TokenType eof = Topology.Converters.WellKnownText.TokenType.Eof;
char[] chArray = new char[1];
this._currentToken = "";
this._currentTokenType = Topology.Converters.WellKnownText.TokenType.Eof;
int num = this._reader.Read(chArray, 0, 1);
bool flag = false;
bool flag2 = false;
byte[] bytes = null;
ASCIIEncoding encoding = new ASCIIEncoding();
char[] chars = null;
while (num != 0)
{
bytes = new byte[] { (byte) this._reader.Peek() };
chars = encoding.GetChars(bytes);
char character = chArray[0];
char ch2 = chars[0];
this._currentTokenType = this.GetType(character);
eof = this.GetType(ch2);
if (flag2 && (character == '_'))
{
this._currentTokenType = Topology.Converters.WellKnownText.TokenType.Word;
}
if (flag2 && (this._currentTokenType == Topology.Converters.WellKnownText.TokenType.Number))
{
this._currentTokenType = Topology.Converters.WellKnownText.TokenType.Word;
}
if ((this._currentTokenType == Topology.Converters.WellKnownText.TokenType.Word) && (ch2 == '_'))
{
eof = Topology.Converters.WellKnownText.TokenType.Word;
flag2 = true;
}
if ((this._currentTokenType == Topology.Converters.WellKnownText.TokenType.Word) && (eof == Topology.Converters.WellKnownText.TokenType.Number))
{
eof = Topology.Converters.WellKnownText.TokenType.Word;
flag2 = true;
}
if (((character == '-') && (eof == Topology.Converters.WellKnownText.TokenType.Number)) && !flag)
{
this._currentTokenType = Topology.Converters.WellKnownText.TokenType.Number;
eof = Topology.Converters.WellKnownText.TokenType.Number;
}
if ((flag && (eof == Topology.Converters.WellKnownText.TokenType.Number)) && (character == '.'))
{
this._currentTokenType = Topology.Converters.WellKnownText.TokenType.Number;
}
if (((this._currentTokenType == Topology.Converters.WellKnownText.TokenType.Number) && (ch2 == '.')) && !flag)
{
eof = Topology.Converters.WellKnownText.TokenType.Number;
flag = true;
}
this._colNumber++;
if (this._currentTokenType == Topology.Converters.WellKnownText.TokenType.Eol)
{
this._lineNumber++;
this._colNumber = 1;
}
this._currentToken = this._currentToken + character;
if (this._currentTokenType != eof)
{
num = 0;
}
else
{
if ((this._currentTokenType == Topology.Converters.WellKnownText.TokenType.Symbol) && (character != '-'))
{
num = 0;
continue;
}
num = this._reader.Read(chArray, 0, 1);
}
}
return this._currentTokenType;
}
示例14: Parse
public static Property Parse(XmlNode firstProperty, string context)
{
Property rootProperty = new Property();
rootProperty.Context = context;
rootProperty.Name = firstProperty.Attributes["name"].Value;
rootProperty.FullName = firstProperty.Attributes["fullname"].Value;
string propType = firstProperty.Attributes["type"].Value;
if (propType != "array" && propType != "object")
{
if (firstProperty.Attributes["encoding"] != null)
{
if (firstProperty.Attributes["encoding"].Value == "base64")
{
byte[] todecode_byte = Convert.FromBase64String(firstProperty.InnerText);
System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();
int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
string result = new String(decoded_char);
rootProperty.Value = result;
}
}
else
{
rootProperty.Value = firstProperty.InnerText;
}
rootProperty.isComplete = true;
rootProperty.Type = PropertyType.Scalar;
return rootProperty;
}
else
{
rootProperty.isComplete = false;
rootProperty.Type = (propType == "array") ? PropertyType.Array : PropertyType.Object;
if (propType == "array")
{
rootProperty.Value = "Array (" + (firstProperty.Attributes["numchildren"] != null ? firstProperty.Attributes["numchildren"].Value : "") + ")";
} else {
rootProperty.Value = "Instance of " + firstProperty.Attributes["classname"].Value;
}
if (firstProperty.Attributes["children"].Value == "0")
{
rootProperty.isComplete = true;
}
else
{
int numChildren = firstProperty.Attributes["numchildren"] != null ? Convert.ToInt32(firstProperty.Attributes["numchildren"].Value) : 0;
rootProperty.isComplete = numChildren > 0 && numChildren == firstProperty.ChildNodes.Count;
foreach (XmlNode node in firstProperty.ChildNodes)
{
if (node.Attributes["name"].Value == "CLASSNAME") continue; // this is to handle http://bugs.xdebug.org/bug_view_page.php?bug_id=00000518
rootProperty.ChildProperties.Add(Property.Parse(node, context));
}
}
}
return rootProperty;
}
示例15: TestUserIdForMbr
public void TestUserIdForMbr() {
string id = "myAdderId";
Adder adder = m_testService.CreateNewWithUserID(id);
string marshalUrl = RemotingServices.GetObjectUri(adder);
Ior adderIor = new Ior(marshalUrl);
IInternetIiopProfile prof = adderIor.FindInternetIiopProfile();
byte[] objectKey = prof.ObjectKey;
ASCIIEncoding enc = new ASCIIEncoding();
string marshalUri = new String(enc.GetChars(objectKey));
Assert.AreEqual(id, marshalUri, "wrong user id");
// check if callable
int arg1 = 1;
int arg2 = 2;
Assert.AreEqual(arg1 + arg2, adder.Add(arg1, arg2), "wrong adder result");
}