public LayoutFit(int numWorkoutsParam, int workoutLengthParam) { workoutLength = workoutLengthParam; lines = new List <LayoutLine>(numWorkoutsParam); //we can only have 17 workouts per layout? //that's how many ****,**** type lines there //are in the Heather sample from which we've //hacked these codes bFs = new List <BinaryFit>(numWorkoutsParam); sFs = new List <SoundFit>(numWorkoutsParam); ASCIIEncoding AE = new ASCIIEncoding(); byte[] me = new byte[1]; //byte me :> :P :) ;) for (int ii = 0; ii < numWorkoutsParam; ii++) //Make our workouts be named workoutA //through workoutQ (and s000023A...s00023Q) { me[0] = lowByte((short)ii); me[0] += 65;//'A' string bFNamer = string.Format("W000000{0}", new String(AE.GetChars(me))); string sFNamer = string.Format("S000000{0}", new String(AE.GetChars(me))); bFs.Add(new BinaryFit(bFNamer, workoutLength)); sFs.Add(new SoundFit(sFNamer)); lines.Add(new LayoutLine(bFNamer, sFNamer)); } }
private void DoNegAOORTest(ASCIIEncoding ascii, byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { Assert.Throws <ArgumentOutOfRangeException>(() => { ascii.GetChars(bytes, byteIndex, byteCount, chars, charIndex); }); }
/// <summary> /// 将字节数组解密成字符串,前提该字节数组已加密 /// </summary> /// <param name="value">值,要解密的字节数组</param> /// <param name="pwd">密匙,使用密匙来解密字符串</param> /// <returns></returns> public static string DecryptFromBytes(this byte[] value, string pwd) { byte[] bytes = CryptBytes(pwd, value, false); var asciiEncoder = new ASCIIEncoding(); return(new string(asciiEncoder.GetChars(bytes))); }
private void VerifyBytesToRead(int numBytesRead) { using (SerialPort com1 = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName)) using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName)) { Random rndGen = new Random(-55); byte[] bytesToWrite = new byte[numRndBytesToRead]; char[] expectedChars; ASCIIEncoding encoding = new ASCIIEncoding(); // Generate random characters for (int i = 0; i < bytesToWrite.Length; i++) { byte randByte = (byte)rndGen.Next(0, 256); bytesToWrite[i] = randByte; } expectedChars = encoding.GetChars(bytesToWrite, 0, bytesToWrite.Length); Debug.WriteLine("Verifying BytesToRead with a buffer of: {0} ", numBytesRead); com1.Open(); com2.Open(); VerifyRead(com1, com2, bytesToWrite, expectedChars, numBytesRead); } }
public static void Main() { Char[] chars; Byte[] bytes = new Byte[] { 65, 83, 67, 73, 73, 32, 69, 110, 99, 111, 100, 105, 110, 103, 32, 69, 120, 97, 109, 112, 108, 101 }; ASCIIEncoding ascii = new ASCIIEncoding(); int charCount = ascii.GetCharCount(bytes, 6, 8); chars = new Char[charCount]; int charsDecodedCount = ascii.GetChars(bytes, 6, 8, chars, 0); Console.WriteLine( "{0} characters used to decode bytes.", charsDecodedCount ); Console.Write("Decoded chars: "); foreach (Char c in chars) { Console.Write("[{0}]", c); } Console.WriteLine(); }
/// <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))); }
/// <summary> /// Read the next block from the socket. /// </summary> private void ReadNextBlock() { var buffer = new byte[1024]; _currentPosition = _actualSize = 0; _actualSize = _socket.Receive(buffer); _ascii.GetChars(buffer, 0, _actualSize, _charBuffer, 0); }
public void LoadFromDisk(string path) { lines.Clear(); int index = path.LastIndexOf(@"\"); string currentDirectory = path.Substring(0, index) + "\\"; byte[] inBuf = new byte[16]; string safe = ""; BinaryReader objFile = null; try { objFile = new BinaryReader(File.Open(path, FileMode.Open)); } catch (Exception except) { MessageBox.Show(except.ToString(), "Loading SoundFit File Error"); } bool bContinue = true; ASCIIEncoding AE = new ASCIIEncoding(); try { while (bContinue) { inBuf = objFile.ReadBytes(16); if (inBuf.Length < 16) { bContinue = false; continue; } string inLine = ""; inLine = new string(AE.GetChars(inBuf)); // index = inLine.LastIndexOf(","); // safe = inLine.Substring(0, index); safe = inLine.Substring(0, 8); if (safe != "********") { lines.Add(new SoundLine(currentDirectory + safe + ".WAV", safe)); } else { lines.Add(new SoundLine());//first "********,*****" line in every sound file? } } } catch (Exception e) { MessageBox.Show(e.ToString() + " From SoundFit.LoadFromDisk()"); bContinue = false; } finally { objFile.Close(); } }
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."); } }
private void ParseLoaderString(byte[] str2) { if (str2[3] == (byte)' ') { var fuses = str2.Take(12).Skip(8).ToArray(); string result = string.Empty; foreach (var i in fuses) { result = result + i.ToString("X") + " "; } result = result.Trim().Replace(' ', '.'); Fuze = result; int proc = 0; str2.Take(7).Skip(4).Select (o => proc = (proc << 8) + o). ToArray(); var vers = new string(str2.Skip(13).Select(o => (char)o).ToArray()); this.Processor = (ProcessorType)proc; double version; if (Double.TryParse(vers.Replace(".", DecimalSeparator), out version)) { this.LoaderVersion = version; } } if (str2[3] == (byte)'*') { var ascii = new ASCIIEncoding(); var devIdStr = new string(ascii.GetChars(str2, 4, 3)); var revIdStr = new string(ascii.GetChars(str2, 8, 4)); string result = string.Format("Dev = 0x{0} Rev = 0x{1}", devIdStr, revIdStr); Fuze = result; } }
public void NegTest5() { ASCIIEncoding ascii = new ASCIIEncoding(); byte[] bytes = null; Assert.Throws <ArgumentNullException>(() => { ascii.GetChars(bytes, 0, 0, new char[0], 0); }); }
public void WriteToFile(string input) { // This method writes the values of the properties at the design time into a Text file DataBindingOutput.txt in the "C" of the system. StreamWriter myFile = File.AppendText("C:\\DataBindingOutput.txt"); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] ByteArray = encoder.GetBytes(input); char[] CharArray = encoder.GetChars(ByteArray); myFile.WriteLine(CharArray, 0, input.Length); myFile.Close(); }
//随即产生一个字母 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]); }
public void WriteToFile(string input) { // The WriteToFile custom method writes // the values of the DataBinding properties // to a file on the C drive at design time. StreamWriter myFile = File.AppendText("C:\\DataBindingOutput.txt"); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] ByteArray = encoder.GetBytes(input); char[] CharArray = encoder.GetChars(ByteArray); myFile.WriteLine(CharArray, 0, input.Length); myFile.Close(); }
public static string AsciiToString(string ascii) { string result = ""; byte[] RxdBuf = StrToHexByte(ascii); // 定义接收缓冲区; for (int i = 0; i < RxdBuf.Length; i++) { ASCIIEncoding ASCIITochar = new ASCIIEncoding(); char[] asc = ASCIITochar.GetChars(RxdBuf); // 将接收字节解码为ASCII字符数组 result += asc[i]; } return(result); }
public static string IntToASCIIString(int iValue) { string result = ""; int formater = 0x000000FF; Byte[] destByte = new Byte[] { (Byte)(iValue & formater), (Byte)((iValue >> 8) & formater) }; ASCIIEncoding ascii = new ASCIIEncoding(); Char[] chars = new Char[2]; ascii.GetChars(destByte, 0, 2, chars, 0); result = chars[0].ToString() + chars[1].ToString(); return(result); }
/// <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; } } } } }
///// <summary> ///// 读卡 ///// </summary> ///// <param name="hadler">打开的串口句柄</param> ///// <param name="sqadd">扇区地址</param> ///// <param name="blockAddr">扇区块地址</param> ///// <returns>读取的值</returns> //public string ReadCard(int sqadd,int blockAddr) //{ // byte[] _BlockData = new byte[10]; // int rs = CRTCard.RF610_S50ReadBlock(RF610CARD.hadler, Convert.ToByte(sqadd), Convert.ToByte(blockAddr), _BlockData, ""); // if (rs == 0) // { // return dis_package(_BlockData); // } // else // { // return ""; // } //} public string dis_package(byte[] reb) { string temp = ""; ASCIIEncoding AE2 = new ASCIIEncoding(); char[] CharArray = AE2.GetChars(reb); for (int x = 0; x <= CharArray.Length - 1; x++) { temp = temp + CharArray[x].ToString(); } return(temp); }
public static string FromBase64String(string str) { if (string.IsNullOrEmpty(str)) { return(string.Empty); } //System.Diagnostics.Contracts.Contract.Assert(str != String.Empty, "str cannot be empty"); ////str = (isUrlSafe) ? FromBase64UrlSafeString(str) : str; ASCIIEncoding AE = new ASCIIEncoding(); char[] carr = new char[AE.GetCharCount(Convert.FromBase64String(str))]; AE.GetChars(Convert.FromBase64String(str), 0, Convert.FromBase64String(str).Length, carr, 0); return(new string(carr)); }
public static void SnippetB() { //<snippet4> ASCIIEncoding AE = new ASCIIEncoding(); byte[] ByteArray = { 69, 110, 99, 111, 100, 105, 110, 103, 32, 83, 116, 114, 105, 110, 103, 46 }; char[] CharArray = AE.GetChars(ByteArray); for (int x = 0; x < CharArray.Length; x++) { Console.Write(CharArray[x]); } //</snippet4> }
private string getImageData(string empno) { string sp = ""; DataSet ds1 = Connection.GetDataSet("select photo from tbl_employeeinfo where empno='" + empno + "'"); Byte[] s = (Byte[])ds1.Tables[0].Rows[0][0]; ASCIIEncoding ascii = new ASCIIEncoding(); char[] charArray = ascii.GetChars(s); for (int i = 0; i < charArray.Length; i++) { sp += charArray[i]; } return(sp); }
private void SerGet_Click(object sender, EventArgs e) { SerNum.Text = ""; Read_array_Triggered = true; System.Threading.Thread.Sleep(1000); ASCIIEncoding ASCIITochar = new ASCIIEncoding(); char[] ascii = ASCIITochar.GetChars((byte[])array_data); for (int i = 0; i < array_length; i++) { SerNum.Text += ascii[i]; } }
private string ToAsciiChars(byte[] bytes, int offset, int count) { if (count == 0) { count = bytes.Length; if (offset != 0) { throw new IndexOutOfRangeException("You cannot take more bytes than the count if offset != 0"); } } ASCIIEncoding e = new ASCIIEncoding(); char[] ch = e.GetChars(bytes, offset, count); return(new string(ch)); }
public void NegTest6() { ASCIIEncoding ascii = new ASCIIEncoding(); byte[] bytes = new byte[] { 65, 83, 67, 73, 73, 32, 69, 110, 99, 111, 100, 105, 110, 103, 32, 69, 120, 97, 109, 112, 108 }; Assert.Throws <ArgumentNullException>(() => { ascii.GetChars(bytes, 0, 0, null, 0); }); }
/// <summary> /// ASCII字符串转化为字符串 /// thy | 2021年1月28日16:12:42 /// </summary> /// <param name="strAsc">长度为3的整数倍</param> /// <returns></returns> public static string Ascii2String(string strAsc) { byte[] bts = new byte[strAsc.Length / 3]; string schar = ""; int j = 0; ASCIIEncoding asci = new ASCIIEncoding(); for (int i = 0; i < strAsc.Length; i = i + 3) { schar = strAsc.Substring(i, 3); bts[j] = byte.Parse(schar); j++; } string str = new String(asci.GetChars(bts)); return(str); }
//yaaay, we have a name generator :D public string NameGenerator() { ASCIIEncoding ascii = new ASCIIEncoding(); string name = ""; int syllables = Random.Range(1, 6); for (int i = 0; i < syllables; i++) { char[] chars = ascii.GetChars(new byte[] { (byte)Random.Range(97, 122), (byte)Random.Range(97, 122) }); foreach (char a in chars) { name += a; } } return(name); }
public static void info_DCM(string nom_fich) { int size = (int)new System.IO.FileInfo(nom_fich).Length; int size1 = size; byte[] Bbuf = new byte[size1]; char[] radh = new char[size1 / 2]; string[] radh1 = new string[size1 / 2]; ASCIIEncoding ascii = new ASCIIEncoding(); Stream Soriginalstream = new FileStream(nom_fich, FileMode.Open, FileAccess.Read); //Soriginalstream.Seek(132, SeekOrigin.Begin); Soriginalstream.Read(Bbuf, 0, size1); Soriginalstream.Close(); char[] encodingName = ascii.GetChars(Bbuf, 0, size1 / 2); int i = 0; string tag1 = null; string tag2 = null; char[] vr = new char [3]; string [] vl = new string[2]; string[] valeur = new string[100]; for (i = 0; i < size1 / 2; i++) { Int16 value = BitConverter.ToInt16(Bbuf, 2 * i); string hex = String.Format("{0:X4}", value); radh1[i] = hex; radh[i] = encodingName[i]; } i = 0; do { tag1 = radh1[i]; tag2 = radh1[i + 1]; i += 1; }while ((tag1 != "7FE0") || (tag2 != "0010")); tail_entet = ((i + 1) * 2) + 6;//((i+1)* 2) + 132+6; # region commentaire
public void GetCharsTest() { ASCIIEncoding target = new ASCIIEncoding(); // TODO: Initialize to an appropriate value byte[] bytes = null; // TODO: Initialize to an appropriate value int byteIndex = 0; // TODO: Initialize to an appropriate value int byteCount = 0; // TODO: Initialize to an appropriate value char[] chars = null; // TODO: Initialize to an appropriate value int charIndex = 0; // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.GetChars(bytes, byteIndex, byteCount, chars, charIndex); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void AcceptMessage() { IPAddress ipAd = IPAddress.Parse("127.0.0.1");//("192.168.1.2");//IPAddress.Any; // use local m/c 1IP address, and // use the same in the client /* Initializes the Listener */ TcpListener myList = new TcpListener(ipAd, 8001); /* Start Listeneting at the specified port */ myList.Start(); StatusbarMsg += "\tThe server is running at port 8001..."; StatusbarMsg += "\tThe local End point is :" + myList.LocalEndpoint; StatusbarMsg += "\nWaiting for a connection....."; Socket s = myList.AcceptSocket(); StatusbarMsg += "\tConnection accepted from " + s.RemoteEndPoint; byte[] b = new byte[100]; int k = s.Receive(b); StatusbarMsg += $"\tRecieved... {k} bytes"; ASCIIEncoding asen = new ASCIIEncoding(); char[] receivedMessage = asen.GetChars(b); string receivedStr = ""; for (int i = 0; i < k; i++) { receivedStr += receivedMessage[i]; } ReceivedMessage = receivedStr; StatusbarMsg += receivedStr; s.Send(asen.GetBytes("The string was recieved by the server.")); StatusbarMsg += "\tSent Acknowledgement"; /* clean up */ s.Close(); myList.Stop(); }
protected virtual string ReadLine() { byte[] bs = null; LineParser linePaser = new LineParser(); ASCIIEncoding aSCIIEncoding = new ASCIIEncoding(); while ((bs = ReadByte()) != null) { linePaser.Write(aSCIIEncoding.GetChars(bs)); string strNextLine = linePaser.ReadLine(); if (strNextLine != null) { return(strNextLine); } } throw new Pop3ServerIncorectAnswerException(); }
private void DoNegAOORTest(ASCIIEncoding ascii, byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { Assert.Throws<ArgumentOutOfRangeException>(() => { ascii.GetChars(bytes, byteIndex, byteCount, chars, charIndex); }); }
private void DoPosTest(ASCIIEncoding ascii, byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { int actualValue = ascii.GetChars(bytes, byteIndex, byteCount, chars, charIndex); Assert.True(VerifyGetCharsResult(ascii, bytes, byteIndex, byteCount, chars, charIndex, actualValue)); }
public void NegTest5() { ASCIIEncoding ascii = new ASCIIEncoding(); byte[] bytes = null; Assert.Throws<ArgumentNullException>(() => { ascii.GetChars(bytes, 0, 0, new char[0], 0); }); }
public void NegTest6() { ASCIIEncoding ascii = new ASCIIEncoding(); byte[] bytes = new byte[] { 65, 83, 67, 73, 73, 32, 69, 110, 99, 111, 100, 105, 110, 103, 32, 69, 120, 97, 109, 112, 108 }; Assert.Throws<ArgumentNullException>(() => { ascii.GetChars(bytes, 0, 0, null, 0); }); }