• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ASCIIEncoding类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ASCIIEncoding的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding类的具体用法?C# ASCIIEncoding怎么用?C# ASCIIEncoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: PostHtmlFromUrl

    /// <summary>
    /// �����������վ��UTF-8���룬Http Post�������Ҳ��Ҫ��UTF-8����
    /// HttpUtility.UrlEncode(merId, myEncoding)
    /// </summary>
    /// <param name="url">���ʵ�ַ����������</param>
    /// <param name="para">�����ַ���</param>
    /// <returns></returns>
    public static string PostHtmlFromUrl(string url, string postData)
    {
        String sResult = "";
        try
        {
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(postData);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
            request.ContentLength = postData.Length;
            Stream stream = request.GetRequestStream();
            stream.Write(data, 0, data.Length);
            stream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string content = reader.ReadToEnd();
            return content;

        }
        catch (Exception e)
        {
            sResult = "-101";
            return sResult;

        }
    }
开发者ID:Fred-Lee,项目名称:AppInOneBPM,代码行数:35,代码来源:SYS_TEMPUSERBack.aspx.cs


示例2: Main

	static int Main ()
	{
		HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://localhost:8081/Default.aspx");
		request.Method = "POST";

		ASCIIEncoding ascii = new ASCIIEncoding ();
		byte [] byData = ascii.GetBytes ("Mono ASP.NET");
		request.ContentLength = byData.Length;
		Stream rs = request.GetRequestStream ();
		rs.Write (byData, 0, byData.Length);
		rs.Flush ();

		try {
			HttpWebResponse response = (HttpWebResponse) request.GetResponse ();
			using (StreamReader sr = new StreamReader (response.GetResponseStream (), Encoding.UTF8, true)) {
				string result = sr.ReadToEnd ();
				if (result.IndexOf ("<p>REQ:0</p>") == -1) {
					Console.WriteLine (result);
					return 1;
				}
			}
			response.Close ();
		} catch (WebException ex) {
			if (ex.Response != null) {
				StreamReader sr = new StreamReader (ex.Response.GetResponseStream ());
				Console.WriteLine (sr.ReadToEnd ());
			} else {
				Console.WriteLine (ex.ToString ());
			}
			return 2;
		}

		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:34,代码来源:test.cs


示例3: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string url = "https://graph.facebook.com/567517451/notifications";

        HttpWebRequest httpWReq =
        (HttpWebRequest)WebRequest.Create(url);

        ASCIIEncoding encoding = new ASCIIEncoding();
        string postData = "access_token=355242331161855|qyYMEnPyR2y3sWK8H7rN-6n3lBU";
        postData += "&template=Test";
        postData += "&href=http://postaround.me";
        byte[] data = encoding.GetBytes(postData);

        httpWReq.Method = "POST";
        httpWReq.ContentType = "application/x-www-form-urlencoded";
        httpWReq.ContentLength = data.Length;

        using (Stream stream = httpWReq.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }

        HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();

        string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
    }
开发者ID:ayaniv,项目名称:PostAroundMe,代码行数:26,代码来源:testFBN.aspx.cs


示例4: Main

    public static void Main()
    {
        try {
            TcpClient tcpclnt = new TcpClient();
            //Console.WriteLine("Connecting.....");

            tcpclnt.Connect("161.115.86.57",8001);
            // use the ipaddress as in the server program

            //Console.WriteLine("Connected");
            //Console.Write("Enter the string to be transmitted : ");

            String sendString = Console.ReadLine();
            Stream serverSendStream = tcpclnt.GetStream();

            ASCIIEncoding asen = new ASCIIEncoding();
            byte[] bytesInSend = asen.GetBytes(sendString);
            //Console.WriteLine("Transmitting.....");

            // send length then string to read to length+1
            serverSendStream.Write(bytesInSend, 0, bytesInSend.Length);

            byte[] bytesToRead = new byte[100];
            int numberOfBytesRead = serverSendStream.Read(bytesToRead, 0, bytesToRead.Length);

            for (int i = 0; i < numberOfBytesRead; i++)
                Console.Write(Convert.ToChar(bytesToRead[i]));

            tcpclnt.Close();
        }

        catch (Exception e) {
            Console.WriteLine("Error..... " + e.StackTrace);
        }
    }
开发者ID:ribler,项目名称:CS-Connection,代码行数:35,代码来源:CSClient.cs


示例5: OnActivate

	public static bool OnActivate()
	{
        
        encoding = new ASCIIEncoding();
		InitializeComponents();
		
		installerForm.ShowDialog();
		
		if (installSelected == false)
			return false;
			
		if (! InstallModuleCore())
			return false;
			
		
		if (cyberwareSelected) {
			if (! InstallModuleCyberware())
				return false;
		}
		
		if (equipmentSelected) {
			if (! InstallModuleEquipment())
				return false;
		}
		
		if (rebalanceSelected) {
			if (! InstallModuleRebalance())
				return false;
		}
		
		return true;
	}
开发者ID:Aldavere,项目名称:project-nevada,代码行数:32,代码来源:script.cs


示例6: CutString

    /// <summary>
    /// 截取字符长度
    /// </summary>
    /// <param name="inputString">字符</param>
    /// <param name="len">长度</param>
    /// <returns></returns>
    public static string CutString(string inputString, int len)
    {
        ASCIIEncoding ascii = new ASCIIEncoding();
            int tempLen = 0;
            string tempString = "";
            byte[] s = ascii.GetBytes(inputString);
            for (int i = 0; i < s.Length; i++)
            {
                if ((int)s[i] == 63)
                {
                    tempLen += 2;
                }
                else
                {
                    tempLen += 1;
                }

                try
                {
                    tempString += inputString.Substring(i, 1);
                }
                catch
                {
                    break;
                }

                if (tempLen > len)
                    break;
            }
            //如果截过则加上半个省略号
            byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString);
            if (mybyte.Length > len)
                tempString += "…";
            return tempString;
    }
开发者ID:priceLiu,项目名称:CMS,代码行数:41,代码来源:Utils.cs


示例7: KalimbaPdImplNetwork

    public KalimbaPdImplNetwork()
    {
        asciiEncoding = new ASCIIEncoding();

        t = new Thread(NetworkRun);
        t.Start();
    }
开发者ID:hagish,项目名称:kalimba-desktop,代码行数:7,代码来源:KalimbaPdImplNetwork.cs


示例8: Main

    public static void Main()
    {
        try
        {

            TcpListener Listener;
            Socket client_socket;
            acceptconnection(out Listener, out client_socket);

            Receive(client_socket);
            //int gh = testReceive(client_socket);

            ASCIIEncoding asen = new ASCIIEncoding();
            client_socket.Send(asen.GetBytes("The string was recieved by the server."));
            Console.WriteLine("\nSent Acknowledgement");

            client_socket.Close();
            Listener.Stop();

        }
        catch (Exception error)
        {
            Console.WriteLine("Error..... " + error.StackTrace);
        }
    }
开发者ID:ribler,项目名称:CS-Connection,代码行数:25,代码来源:Server.cs


示例9: DoNegAOORTest

 private void DoNegAOORTest(ASCIIEncoding ascii, int charCount)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         ascii.GetMaxByteCount(charCount);
     });
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:ASCIIEncodingGetMaxByteCount.cs


示例10: DoPosTest

        private void DoPosTest(ASCIIEncoding ascii, string source, int charIndex, int count, byte[] bytes, int byteIndex)
        {
            int actualValue;

            actualValue = ascii.GetBytes(source, charIndex, count, bytes, byteIndex);
            Assert.True(VerifyASCIIEncodingGetBytesResult(ascii, source, charIndex, count, bytes, byteIndex, actualValue));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:ASCIIEncodingGetBytes1.cs


示例11: sendMessage

 public static void sendMessage(Socket clientSocket)
 {
     ASCIIEncoding asn = new ASCIIEncoding();
     String sendString = Console.ReadLine();
     //String sendString = "This is a test!!!!!!!!!!!!!!!!!!!!!!!!";
     clientSocket.Send(asn.GetBytes(sendString));
 }
开发者ID:ribler,项目名称:CS-Connection,代码行数:7,代码来源:Program.cs


示例12: RunTest

	static void RunTest ()
	{
		// Start the server thread
		ServerThread serverThread = new ServerThread ();
		serverThread.Start ();

		// Create the client
		HttpWebRequest rq = (HttpWebRequest) WebRequest.Create ("http://" + IPAddress.Loopback.ToString () + ":54321");
		rq.ProtocolVersion = HttpVersion.Version11;
		rq.KeepAlive = false;

		// Get the response
		HttpWebResponse rsp = (HttpWebResponse) rq.GetResponse ();
		ASCIIEncoding enc = new ASCIIEncoding ();

		StringBuilder result = new StringBuilder ();

		// Stream the body in 1 byte at a time
		byte [] bytearr = new byte [1];
		Stream st = rsp.GetResponseStream ();
		while (true) {
			int b = st.Read (bytearr, 0, 1);
			if (b == 0) {
				break;
			}

			result.Append (enc.GetString (bytearr));
		}

		Assert.AreEqual ("012345670123456789abcdefabcdefghijklmnopqrstuvwxyz",
			result.ToString (), "#1");
	}
开发者ID:mono,项目名称:gert,代码行数:32,代码来源:test.cs


示例13: DoPosTest

 private void DoPosTest(ASCIIEncoding ascii, int byteCount, int expectedValue)
 {
     int actualValue;
     ascii = new ASCIIEncoding();
     actualValue = ascii.GetMaxCharCount(byteCount);
     Assert.Equal(expectedValue, actualValue);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:ASCIIEncodingGetMaxCharCount.cs


示例14: echoMessage

 public static int echoMessage(Socket clientSocket)
 {
     string messageToSend = testReceive(clientSocket);
     ASCIIEncoding asn = new ASCIIEncoding();
     clientSocket.Send(asn.GetBytes(messageToSend));
     return messageToSend.Length;
 }
开发者ID:ribler,项目名称:CS-Connection,代码行数:7,代码来源:Program.cs


示例15: TryConnect

    //пытаемся отправить кому-то сообщение о том, что хотим понаблюдать за его игрой
    //если прокатывает - в ответ нам начнут приходить сообщения о состоянии игры
    public void TryConnect(string ip, string port)
    {
        try
        {
            TcpClient tcpclnt = new TcpClient();
            tcpclnt.Connect(IPAddress.Parse(ip), int.Parse(port));
            String str = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
            Stream stm = tcpclnt.GetStream();

            ASCIIEncoding asen = new ASCIIEncoding();
            byte[] ba = asen.GetBytes(str);
            stm.Write(ba, 0, ba.Length);
            byte[] bb = new byte[255];
            int k = stm.Read(bb, 0, 255);

            string an = "";
            for (int i = 0; i < k; i++)
                an += Convert.ToChar(bb[i]);

            stm.Close();
            tcpclnt.Close();
        }
        catch (Exception e)
        {
            Debug.LogError(e.StackTrace);
        }
    }
开发者ID:BoogieGo,项目名称:avegames_task,代码行数:29,代码来源:NetworkManager.cs


示例16: Main

	public static void Main() {
		
		try {
			TcpClient tcpclnt = new TcpClient();
			Console.WriteLine("Connecting.....");
			
			tcpclnt.Connect("172.21.5.99",8001); // use the ipaddress as in the server program
			
			Console.WriteLine("Connected");
			Console.Write("Enter the string to be transmitted : ");
			
			String str=Console.ReadLine();
			Stream stm = tcpclnt.GetStream();
						
			ASCIIEncoding asen= new ASCIIEncoding();
			byte[] ba=asen.GetBytes(str);
			Console.WriteLine("Transmitting.....");
			
			stm.Write(ba,0,ba.Length);
			
			byte[] bb=new byte[100];
			int k=stm.Read(bb,0,100);
			
			for (int i=0;i<k;i++)
				Console.Write(Convert.ToChar(bb[i]));
			
			tcpclnt.Close();
		}
		
		catch (Exception e) {
			Console.WriteLine("Error..... " + e.StackTrace);
		}
	}
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:33,代码来源:clnt.cs


示例17: DoPosTest

 private void DoPosTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
 {
     int actualValue;
     ascii = new ASCIIEncoding();
     actualValue = ascii.GetCharCount(bytes, index, count);
     Assert.Equal(count, actualValue);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:ASCIIEncodingGetCharCount.cs


示例18: stringToBase64

 //============================================================================
 public static String stringToBase64(String str)
 {
     var encoding = new ASCIIEncoding();
     byte[] buf = encoding.GetBytes(str);
     int size = buf.Length;
     char[] ar = new char[((size + 2) / 3) * 4];
     int a = 0;
     int i = 0;
     while (i < size)
     {
         byte b0 = buf[i++];
         byte b1 =(byte) ((i < size) ? buf[i++] : 0);
         byte b2 = (byte) ((i < size) ? buf[i++] : 0);
         ar[a++] = BASE64_ALPHABET[(b0 >> 2) & 0x3f];
         ar[a++] = BASE64_ALPHABET[((b0 << 4) | ((b1 & 0xFF) >> 4)) & 0x3f];
         ar[a++] = BASE64_ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & 0x3f];
         ar[a++] = BASE64_ALPHABET[b2 & 0x3f];
     }
     int o=0;
     switch (size % 3)
     {
         case 1: ar[--a] = '='; break;
         case 2: ar[--a] = '='; break;
     }
     return new String(ar);
 }
开发者ID:skorpioniche,项目名称:MinMVC,代码行数:27,代码来源:Miner.cs


示例19: VerifyASCIIEncodingGetBytesResult

        private bool VerifyASCIIEncodingGetBytesResult(
                               ASCIIEncoding ascii,
                               char[] chars, int charIndex, int count,
                               byte[] bytes, int byteIndex,
                               int actualValue)
        {
            if (0 == chars.Length) return 0 == actualValue;

            int currentCharIndex; //index of current encoding character
            int currentByteIndex; //index of current encoding byte
            int charEndIndex = charIndex + count - 1;

            for (currentCharIndex = charIndex, currentByteIndex = byteIndex;
                 currentCharIndex <= charEndIndex; ++currentCharIndex)
            {
                if (chars[currentCharIndex] <= c_MAX_ASCII_CHAR &&
                    chars[currentCharIndex] >= c_MIN_ASCII_CHAR)
                { //verify normal ASCII encoding character
                    if ((int)chars[currentCharIndex] != (int)bytes[currentByteIndex])
                    {
                        return false;
                    }
                    ++currentByteIndex;
                }
                else //Verify ASCII encoder replacment fallback
                {
                    ++currentByteIndex;
                }
            }

            return actualValue == (currentByteIndex - byteIndex);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:32,代码来源:ASCIIEncodingGetBytes2.cs


示例20: sendMessage

 public string sendMessage()
 {
     ASCIIEncoding encoding = new ASCIIEncoding();
     Byte[] userPassBytes = encoding.GetBytes(String.Format("{0}:{1}", appId, password));
     String authHeader = "Authorization: Basic " + (Convert.ToBase64String(userPassBytes));
     string postData = "version=1.0" + "&address=" + address + "&message=" + message;
     byte[] byteArray = encoding.GetBytes(postData);
     WebRequest request = WebRequest.Create("http://192.168.0.250:65182/");
     request.Headers.Add(authHeader);
     request.Method = "POST";
     request.ContentType = "application/x-www-form-urlencoded";
     request.ContentLength = byteArray.Length;
     Stream dataStream = request.GetRequestStream();
     dataStream.Write(byteArray, 0, byteArray.Length);
     dataStream.Close();
     WebResponse response = request.GetResponse();
     Console.WriteLine(((HttpWebResponse)response).StatusDescription);
     dataStream = response.GetResponseStream();
     StreamReader reader = new StreamReader(dataStream);
     string responseFromServer = reader.ReadToEnd();
     reader.Close();
     dataStream.Close();
     response.Close();
     return responseFromServer;
 }
开发者ID:sanyaade,项目名称:aventura-client-api,代码行数:25,代码来源:MtMessageSender.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ASN1类代码示例发布时间:2022-05-24
下一篇:
C# APPBARDATA类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap