当前位置: 首页>>代码示例>>C#>>正文


C# ASCIIEncoding.GetByteCount方法代码示例

本文整理汇总了C#中System.Text.ASCIIEncoding.GetByteCount方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.GetByteCount方法的具体用法?C# ASCIIEncoding.GetByteCount怎么用?C# ASCIIEncoding.GetByteCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.ASCIIEncoding的用法示例。


在下文中一共展示了ASCIIEncoding.GetByteCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoPosTest

 private void DoPosTest(string source, int expectedValue)
 {
     ASCIIEncoding ascii;
     int actualValue;
     ascii = new ASCIIEncoding();
     actualValue = ascii.GetByteCount(source);
     Assert.Equal(expectedValue, actualValue);
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:8,代码来源:ASCIIEncodingGetByteCount1.cs

示例2: DoPosTest

        private void DoPosTest(char[] chars, int startIndex, int count, int expectedValue)
        {
            ASCIIEncoding ascii;
            int actualValue;

            ascii = new ASCIIEncoding();
            actualValue = ascii.GetByteCount(chars, startIndex, count);
            Assert.Equal(expectedValue, actualValue);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:9,代码来源:ASCIIEncodingGetByteCount2.cs

示例3: NegTest1

 public void NegTest1()
 {
     ASCIIEncoding ascii;
     string source = null;
     ascii = new ASCIIEncoding();
     Assert.Throws<ArgumentNullException>(() =>
     {
         ascii.GetByteCount(source);
     });
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:10,代码来源:ASCIIEncodingGetByteCount1.cs

示例4: NegTest1

        public void NegTest1()
        {
            ASCIIEncoding ascii;
            char[] chars = null;

            ascii = new ASCIIEncoding();
            Assert.Throws<ArgumentNullException>(() =>
            {
                ascii.GetByteCount(chars, 0, 0);
            });
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:11,代码来源:ASCIIEncodingGetByteCount2.cs

示例5: PosTest2

        public void PosTest2()
        {
            ASCIIEncoding ascii;
            byte[] bytes;
            int byteIndex, byteCount;
            char[] chars;
            int charIndex;
            string source;

            ascii = new ASCIIEncoding();
            source = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            bytes = new byte[ascii.GetByteCount(source)];
            ascii.GetBytes(source, 0, source.Length, bytes, 0);
            byteIndex = TestLibrary.Generator.GetInt32(-55) % bytes.Length;
            byteCount = TestLibrary.Generator.GetInt32(-55) % (bytes.Length - byteIndex) + 1;
            chars = new char[byteCount + TestLibrary.Generator.GetInt32(-55) % c_MAX_STRING_LENGTH];
            charIndex = TestLibrary.Generator.GetInt32(-55) % (chars.Length - byteCount + 1);

            DoPosTest(ascii, bytes, byteIndex, byteCount, chars, charIndex);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:20,代码来源:ASCIIEncodingGetChars.cs

示例6: PosTest2

        public void PosTest2()
        {
            ASCIIEncoding ascii;
            char[] chars;
            int charIndex, count;
            byte[] bytes;
            int byteIndex;

            ascii = new ASCIIEncoding();
            InitializeCharacterArray(out chars);
            charIndex = _generator.GetInt32(-55) % chars.Length;
            count = _generator.GetInt32(-55) % (chars.Length - charIndex) + 1;

            int minLength = ascii.GetByteCount(chars, charIndex, count);
            int length = minLength + _generator.GetInt32(-55) % (Int16.MaxValue - minLength);
            bytes = new byte[length];
            for (int i = 0; i < bytes.Length; ++i)
            {
                bytes[i] = 0;
            }
            byteIndex = _generator.GetInt32(-55) % (bytes.Length - minLength + 1);

            DoPosTest(ascii, chars, charIndex, count, bytes, byteIndex);
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:24,代码来源:ASCIIEncodingGetBytes2.cs

示例7: PosTest2

        public void PosTest2()
        {
            ASCIIEncoding ascii;
            string source;
            int charIndex, count;
            byte[] bytes;
            int byteIndex;

            ascii = new ASCIIEncoding();
            source = _generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            charIndex = _generator.GetInt32(-55) % source.Length;
            count = _generator.GetInt32(-55) % (source.Length - charIndex) + 1;

            int minLength = ascii.GetByteCount(source.Substring(charIndex, count));
            int length = minLength + _generator.GetInt32(-55) % (Int16.MaxValue - minLength);
            bytes = new byte[length];
            for (int i = 0; i < bytes.Length; ++i)
            {
                bytes[i] = 0;
            }
            byteIndex = _generator.GetInt32(-55) % (bytes.Length - minLength + 1);

            DoPosTest(ascii, source, charIndex, count, bytes, byteIndex);
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:24,代码来源:ASCIIEncodingGetBytes1.cs

示例8: HandleClientComm

        /// <summary>
        /// Handles communication with the clients
        /// </summary>
        /// <param name="client"></param>
        private void HandleClientComm(object client)
        {
            String gamerID = "";
            String sentString = "";
            ASCIIEncoding encoder = new ASCIIEncoding();
            TcpClient tcpClient = (TcpClient)client;
            NetworkStream clientStream = tcpClient.GetStream();

            byte[] message = new byte[4096];
            int bytesRead;

            bytesRead = 0;

            try
            {
                //blocks until a client sends a message
                bytesRead = clientStream.Read(message, 0, 4096);
            }
            catch
            {
            }
            //message has successfully been received

            sentString = encoder.GetString(message, 0, bytesRead);
            string[] tokens = sentString.Split(":".ToCharArray());

            if (tokens.Length > 1)//We're getting an update string, so update
            {
                Console.WriteLine("Player Update data for " + tokens[1] + " recieved.");
                PlayerInfo info = new PlayerInfo(sentString);
                UpdatePlayerInfo(info);
                gamerID = info.PlayerName;
            }
            else
            {
                gamerID = sentString;
            }

            //If we have an ID, write the data back
            if (gamerID != "")
            {
                Console.WriteLine("GamerTag = " + gamerID);
                PlayerInfo info = GetPlayerInfo(gamerID);
                byte[] infoBytes = encoder.GetBytes(info.ToString());
                clientStream.Write(infoBytes, 0, encoder.GetByteCount(info.ToString()));
                clientStream.Flush();
            }

            tcpClient.Close();
        }
开发者ID:RobinLieson,项目名称:ar-battle-boats,代码行数:54,代码来源:Server.cs

示例9: NegTest8

        public void NegTest8()
        {
            ASCIIEncoding ascii;
            char[] chars;
            int charIndex, count;
            byte[] bytes;
            int byteIndex;

            ascii = new ASCIIEncoding();
            InitializeCharacterArray(out chars);
            charIndex = _generator.GetInt32(-55) % chars.Length;
            count = _generator.GetInt32(-55) % (chars.Length - charIndex) + 1;
            int minLength = ascii.GetByteCount(chars, charIndex, count);
            bytes = new byte[_generator.GetInt32(-55) % minLength];
            byteIndex = 0;

            Assert.Throws<ArgumentException>(() =>
            {
                ascii.GetBytes(chars, charIndex, count, bytes, byteIndex);
            });
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:21,代码来源:ASCIIEncodingGetBytes2.cs

示例10: EncoderParameter

        public EncoderParameter(Encoder encoder, string value)
        {
            this.encoder = encoder;

            ASCIIEncoding ascii = new ASCIIEncoding();
            int asciiByteCount = ascii.GetByteCount(value);
            byte[] bytes = new byte[asciiByteCount];
            ascii.GetBytes(value, 0, value.Length, bytes, 0);

            this.valuesCount = bytes.Length;
            this.type = EncoderParameterValueType.ValueTypeAscii;
            this.valuePtr = Marshal.AllocHGlobal(valuesCount);
            Marshal.Copy(bytes, 0, this.valuePtr, valuesCount);
        }
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:14,代码来源:EncoderParameter.cs

示例11: Main

  public static int Main(string[] args) {

    /**
     * Get the arguments
     */
    if( args.Length < 2 ) {
      Console.Error.WriteLine("usage: SNodeExample.exe [tcp|udp] port remota_ta0 remote_ta1 ...");
      return 0;
    }

    /**
     * Make the edge listener:
     */
    EdgeListener el = null;
    int port = Int32.Parse( args[1] );
    if( args[0].ToLower() == "tcp" ) {
      el = new TcpEdgeListener(port);
    }
    else if( args[0].ToLower() == "udp" ) {
      el = new UdpEdgeListener(port);
    }
    /**
     * Create a random address for our node.
     * Some other application might want to select the address
     * a particular way, or reuse a previously selected random
     * address.  If the addresses are not random (or the output
     * of secure hashes) the network might not behave correctly.
     */
    RandomNumberGenerator rng = new RNGCryptoServiceProvider();
    AHAddress tmp_add = new AHAddress(rng);
    Console.WriteLine("Address: {0}", tmp_add);
    /**
     * Make the node that lives in a particular
using Brunet.Messaging;
     * namespace (or realm) called "testspace"
     */
    Node tmp_node = new StructuredNode(tmp_add, "testspace");
    ReqrepManager rrman = tmp_node.Rrm;
    ReqrepExample irh = new ReqrepExample();
    tmp_node.GetTypeSource(PType.Protocol.Chat).Subscribe(irh, tmp_node);
    /**
     * Add the EdgeListener
     */
    tmp_node.AddEdgeListener( el );
    /**
     * Tell the node who it can connect to:
     */
    for(int i = 2; i < args.Length; i++) {
      tmp_node.RemoteTAs.Add( TransportAddressFactory.CreateInstance( args[i] ) );
    }
    /**
     * Now we connect
     */
    tmp_node.Connect();
    Console.WriteLine("Connected");
    /**
     * In a real application, we would create some IAHPacketHandler
     * objects and do:
     * tmp_node.Subscribe( )
     * finally, we could send packets using tmp_node.Send( ) or
     * tmp_node.SendTo( )
     */
    string msg = "";
    System.Text.Encoding coder = new System.Text.ASCIIEncoding();
    while( true ) {
     Console.Write("To: ");
     msg = Console.ReadLine();
     if ( msg == "q" ) { break; }
     Address dest = AddressParser.Parse(msg);
     while( msg != "." ) {
      msg = Console.ReadLine();
      int length = coder.GetByteCount(msg);
      byte[] payload = new byte[length];
      coder.GetBytes(msg, 0, msg.Length, payload, 0);
      ISender sender = new AHSender(tmp_node, dest);
      rrman.SendRequest(sender, ReqrepManager.ReqrepType.Request,
                        new CopyList(PType.Protocol.Chat, MemBlock.Reference(payload)),
			irh , null);
     }
    }
	 
    return 1;
  }
开发者ID:johnynek,项目名称:brunet,代码行数:83,代码来源:ReqrepExample.cs

示例12: StringToMemoryStream

 /// <summary>
 /// Converts a string to a MemoryStream.
 /// </summary>
 static MemoryStream StringToMemoryStream(string s)
 {
     System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
     int byteCount = enc.GetByteCount(s.ToCharArray(), 0, s.Length);
     byte[] ByteArray = new byte[byteCount];
     int bytesEncodedCount = enc.GetBytes(s, 0, s.Length, ByteArray, 0);
     System.IO.MemoryStream ms = new System.IO.MemoryStream(ByteArray);
     return ms;
 }
开发者ID:alienlab,项目名称:Alienlab.Zip.Reduced,代码行数:12,代码来源:ZlibUnitTest1.cs

示例13: UpdateInfoOnServer

        /// <summary>
        /// Connects to the Remote Server and Updates the Player Info on it
        /// </summary>
        /// <param name="Server_address">Address of the Remote Server</param>
        /// <param name="Port_Num">Port Number on the Remote Server</param>
        /// <returns>True if update was successful, false otherwise</returns>
        private bool UpdateInfoOnServer(string Server_address, int Port_Num)
        {
            NetworkStream stream; //Stream to write and read data to

            ASCIIEncoding encoder = new ASCIIEncoding();

            TcpClient client = new TcpClient();
            IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3550);

            try
            {
                Console.Write("Connecting to server...");
                client.Connect(serverEndPoint);

                Console.WriteLine("Connected!");

                Console.Write("Sending data to server...");
                //Write the GamerTag to the server

                stream = client.GetStream();
                stream.Write(encoder.GetBytes(ToString()), 0, encoder.GetByteCount(ToString()));
                stream.Flush();

                Console.WriteLine("Data sent!");

                Console.Write("Reading return data...");
                byte[] msg = new byte[4096];
                int read = stream.Read(msg, 0, 4096);
                string message = "";

                if (read > 0)
                {
                    Console.WriteLine("Data returned!");
                    message = encoder.GetString(msg, 0, read);
                }
                else
                {
                    Console.WriteLine("ERROR: No Data returned!");
                    return false;
                }

            }
            catch
            {
                Console.WriteLine("ERROR:  Could not connect to server!");
                return false;
            }

            return true;
        }
开发者ID:RobinLieson,项目名称:ar-battle-boats,代码行数:56,代码来源:PlayerInfo.cs

示例14: GetPlayerInfoFromServer

        /// <summary>
        /// Retrieves the PlayerInfo from the given server
        /// </summary>
        /// <param name="PlayerName">PlayerName of the info to retriver</param>
        /// <param name="Server_Address">Address of the remoter server</param>
        /// <param name="Port_Num">Port on the remote server</param>
        /// <returns>True if the retrieval was successful, False otherwise</returns>
        public bool GetPlayerInfoFromServer(string PlayerName, string Server_Address, int Port_Num)
        {
            NetworkStream stream; //Stream to write and read data to

            ASCIIEncoding encoder = new ASCIIEncoding();

            TcpClient client = new TcpClient();
            IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(Server_Address), Port_Num);

            try
            {
                Console.Write("Connecting to server...");
                client.Connect(serverEndPoint);

                Console.WriteLine("Connected!");

                Console.Write("Sending data to server...");
                //Write the GamerTag to the server

                String tag = "thenewzerov";
                stream = client.GetStream();
                stream.Write(encoder.GetBytes(tag), 0, encoder.GetByteCount(tag));
                stream.Flush();

                Console.WriteLine("Data sent!");

                Console.Write("Reading return data...");
                byte[] msg = new byte[4096];
                int read = stream.Read(msg, 0, 4096);
                string message = "";

                if (read > 0)
                {
                    Console.WriteLine("Data returned!");
                    message = encoder.GetString(msg, 0, read);
                }
                else
                {
                    Console.WriteLine("ERROR: No Data returned!");
                    return false;
                }

                CreateFromString(message);

                Console.WriteLine(ToString());
                return true;
            }
            catch
            {
                Console.WriteLine("ERROR:  Could not connect to server!");
                return false;
            }
        }
开发者ID:RobinLieson,项目名称:ar-battle-boats,代码行数:60,代码来源:PlayerInfo.cs

示例15: NegTest8

        public void NegTest8()
        {
            ASCIIEncoding ascii;
            string source;
            int charIndex, count;
            byte[] bytes;
            int byteIndex;

            ascii = new ASCIIEncoding();
            source = _generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            charIndex = _generator.GetInt32(-55) % source.Length;
            count = _generator.GetInt32(-55) % (source.Length - charIndex) + 1;
            int minLength = ascii.GetByteCount(source.Substring(charIndex, count));
            bytes = new byte[_generator.GetInt32(-55) % minLength];
            byteIndex = 0;

            Assert.Throws<ArgumentException>(() =>
           {
               ascii.GetBytes(source, charIndex, count, bytes, byteIndex);
           });
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:21,代码来源:ASCIIEncodingGetBytes1.cs


注:本文中的System.Text.ASCIIEncoding.GetByteCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。