C#中listBox,如何让他的输出结果以\t的方式输出,而不是换行呢?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#中listBox,如何让他的输出结果以\t的方式输出,而不是换行呢?相关的知识,希望对你有一定的参考价值。
listBox1.Items.Add(a[i].ToString());
参考技术A ListBox只能是一项一行来显示的,不能实现你要的功能,如果要做的话,可以试试TextBox或其他控件本回答被提问者采纳 参考技术B String output = "";在循环体内
output = a[i].ToString() + "\t";
listBox1.items.Add(output); 参考技术C Console.WriteLine("0\t",在这写你要输出的字符串); 参考技术D 你可以搜索你的字符串 找到特定的符号然后把他替换成\T试试?
c# HttpWebResponse判断返回请求的问题
目前已经从listbox1中读取数据,以HttpWebRequest提交到网页,现在以HttpWebResponse方式获取返回信息。
for (int i = 0; i < listBox1.Items.Count; i++)
req = (HttpWebRequest)WebRequest.Create(listBox1.Items[i].ToString() + "?action=login&usr=admin&pwd=admin");
res = (HttpWebResponse)req.GetResponse();
res.Close();
req.Abort();
System.Threading.Thread.Sleep(500);
这是现在的代码。希望判断如果返回admin_default.asp则把listBox1.Items[i].ToString() + "?action=login&usr=admin&pwd=admin"中的内容写到listbox2中。希望高手给段代码。。吼吼,就30分了全部拿出来。今晚在线等答案。谢谢各位了。。。
HttpReceiveData.aspx
///
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HttpReceiveData.aspx.cs" Inherits="HttpReceiveData" %>
HttpReceiveData.aspx.cs
///////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class HttpReceiveData : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
Response.Clear();
Response.Write("nihao" + Request.Form["Desc"] + Request.Form["Title"]);
Response.End();
////string c = Request.Form["nihao"].ToString();
//String a = Request.Form["Title"].ToString();
//String b = Request.Form["Desc"].ToString();
//Common d = new Common();
//d.ShowMessage(this, a + b);
HttpSendData.aspx
//
<%@ Page language="c#" %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.Collections" %>
<%@ Import Namespace = "System.Web" %>
<%@ Import Namespace = "System.Web.UI" %>
<%@ Import Namespace = "System.Web.UI.WebControls" %>
<%@ Import Namespace = "System.Net" %>
<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Text" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<script type="text/C#" runat="server">
void Button1_Click(object sender, System.EventArgs e)
string strTitle = TextBox1.Text;
string strDesc = TextBox2.Text;
//Encoding encoding = Encoding.GetEncoding("GB2312");
//string postData = "Title=" + strTitle;
//string strUrl = "http://localhost/ht/HttpReceiveData.aspx";
//postData += ("&Desc=" + strDesc);
//byte[] data = encoding.GetBytes(postData);
//// 准备请求...
//HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
//myRequest.Method = "POST";
//myRequest.ContentType="application/x-www-form-urlencoded";
//myRequest.ContentLength = data.Length;
//Stream newStream=myRequest.GetRequestStream();
//// 发送数据
//newStream.Write(data,0,data.Length);
//newStream.Close();
CookieContainer cc = new CookieContainer();
string postData = "Title=" + strTitle;
//string strUrl = "http://localhost/ht/HttpReceiveData.aspx";
postData += ("&Desc=" + strDesc);
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create("http://localhost/ht/HttpReceiveData.aspx");
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
long t = response2.ContentLength;
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default);
string text2 = sr2.ReadToEnd();
Response.Redirect("HttpSendData.aspx");
</script>
</HEAD>
<body>
<form id="HTTPPost" method="post" runat="server">
标题:<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<br>
内容:
<br>
<asp:TextBox id="TextBox2" runat="server" TextMode="MultiLine" Rows="10" Columns="100"></asp:TextBox>
<br>
<asp:Button id="Button1" runat="server" Text=" 发 送 " onclick="Button1_Click"></asp:Button>
</form>
</body>
</HTML>
HttpSendData.aspx文件
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class HttpSendData : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
参考技术A 晕倒,搞个功能贴那么长,其实很简单。
for (int i = 0; i < listBox1.Items.Count; i++)
req = (HttpWebRequest)WebRequest.Create(listBox1.Items[i].ToString() + "?action=login&usr=admin&pwd=admin");
res = (HttpWebResponse)req.GetResponse();
if(res.StatusCode == HttpStatusCode.Found)
//这里就跳转了,登录成功
else
//否则就读取内容
System.IO.StreamReader sr=new System.IO.StreamReader(res.GetResponseStream());
string content=sr.ReadToEnd(); //这里的content就是网页内容了
sr.Close();
//判断错误信息
if(content.IndexOf("用户名或密码错误")!=-1)
//用户名密码错误?
else
//其它信息
res.Close();
req.Abort();
System.Threading.Thread.Sleep(500);
注意一个问题,就是网页的编码问题,可能你需要调整new System.IO.StreamReader(res.GetResponseStream());这句话使用指定的编码来读取,否则可能会乱码。本回答被提问者采纳 参考技术B 想实现啥功能?
以上是关于C#中listBox,如何让他的输出结果以\t的方式输出,而不是换行呢?的主要内容,如果未能解决你的问题,请参考以下文章