使用应用程序来解析robots.txt.我自己写了一个从网络服务器中提取文件的方法,并将输出放入文本框.我希望输出显示文件中每一行的单行文本,就像你正常查看robots.txt时一样,但是我的文本框中的输出是所有文本行而没有回车或换行.所以我觉得我很狡猾,为所有的线做一个字符串[],做一个foreach循环,一切都会很好.唉,这不起作用,所以我想我会尝试System.Enviornment.Newline,仍然无法正常工作.这是现在听起来的代码....我怎么能改变这个,所以我得到了robots.txt的所有单独行,而不是拼凑在一起的一堆文本?
public void getRobots()
{
WebClient wClient = new WebClient();
string url = String.Format("http://{0}/robots.txt", urlBox.Text);
try
{
Stream data = wClient.OpenRead(url);
StreamReader read = new StreamReader(data);
string[] lines = new string[] { read.ReadToEnd() };
foreach (string line in lines)
{
textBox1.AppendText(line + System.Environment.NewLine);
}
}
catch (WebException ex)
{
MessageBox.Show(ex.Message, null, MessageBoxButtons.OK);
}
}
Run Code Online (Sandbox Code Playgroud) 让自己成为密码管理器,我遇到了一段代码问题.应该发生的是应用程序打开一个xml文件,然后使用该xml文档中包含的项目(帐户)填充listview.右键单击列表视图可以为各种选项提供上下文菜单,所有选项都可以单独使用.但是,打开xml文档,然后从列表视图中删除其中一个帐户,然后尝试添加另一个帐户,它会抛出以下内容:
ArgumentOutOfRangeException unhandled.
InvalidArgument=Value of '4' is not valid for 'index'.
Parameter name: index
Run Code Online (Sandbox Code Playgroud)
我假设什么是错误的是当我从列表视图中删除帐户时,我搞乱了索引变量的计数,该变量在应用程序启动时为xml文档中的每个项目递增.不确定在不破坏其他代码部分的情况下解决问题的最佳方法.我想通过计算listView中现在有多少项目来删除帐户后重新设置'index'的值,但不确定这是否最佳.这是打开xml时代码的样子.
private void openPasswordFileToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Xml.XmlDocument loadDoc = new System.Xml.XmlDocument();
try
{
loadDoc.Load(Application.StartupPath + "\\database.xml");
}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("Password Database does not exist!");
}
foreach (System.Xml.XmlNode node in loadDoc.SelectNodes("/Database/Account"))
{
lvItem = listView1.Items.Insert(index, node.Attributes["Description"].InnerText); ;
lvItem.SubItems.Add(new ListViewItem.ListViewSubItem(lvItem, node.Attributes["Username"].InnerText)); ;
lvItem.SubItems.Add(new ListViewItem.ListViewSubItem(lvItem, node.Attributes["Password"].InnerText)); ;
index += 1;
}
}
Run Code Online (Sandbox Code Playgroud)
最后删除帐户的细分:
private void removeSelectedAccountToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.Items.Remove(listView1.SelectedItems[0]);
}
Run Code Online (Sandbox Code Playgroud)
在执行以下序列之前,一切都正常工作:帐户文件已打开 - >帐户已删除 - …
很难找到解决这个问题的最佳方法.我发现的是一个装有图像的图库视图,下面是文本视图.我想根据点击的图像填写textview的内容.我遵循标准的GalleryView教程,您可以在其中创建一个扩展BaseAdapter类的自定义ImageAdapter类.在这样做的过程中,我为galleryview创建了一个OnItemClickListener,我假设下一个逻辑步骤是创建一个switch语句来确定在文本视图中放置什么.
所以我最终发现我应该迭代画廊项而不是传递给onitemclicklistener()方法的参数.现在的问题是,无论点击什么项目,所需文本视图的输出总是好像最后一个项目被点击一样.我注释掉了"案例2",然后开始总是采用案例1.即使我没有定义默认案例,什么会导致switch语句'默认'到最后一个案例编码?
另外,我在循环方面看到有关switch语句的冲突.它应该自行循环,是吗?如果是这样,我想它可能是,但因为它总是选择案例2,我没有意识到文本的输出应该改变?我的switch语句都搞砸了吗?我需要包含某种循环吗?我在这做错了什么?
自定义ImageAdapter类:
public class ImageAdapter extends BaseAdapter
{
private Context context;
private int itemBackground;
public ImageAdapter(Context c)
{
context = c;
//---setting the style---
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
//---returns the number of images---
public int getCount() {
return imageIDs.length;
}
//---returns the ID of an item---
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
//---returns an ImageView view---
public View getView(int position, View …Run Code Online (Sandbox Code Playgroud) 在excel上使用一些VBA,我编写了一个用户定义的函数来根据行号进行一些算术运算.它似乎乍一看,然后我意识到无论它总是执行什么,好像第一个If声明是真的,并且从未考虑过ElseIf.我究竟做错了什么?
Function redProfit(ByVal myRange As Range) As Long
Dim rangerow As Range, baseprofit As Long
Application.Volatile
baseprofit = 3500000
With myRange
If (.Row = 3 Or 11) Then
redProfit = baseprofit * 0.1
ElseIf (.Row = 4 Or 10) Then
redProfit = baseprofit * 0.08
ElseIf (.Row = 5 Or 9) Then
redProfit = baseprofit * 0.07
ElseIf (.Row = 6 Or 8) Then
redProfit = baseprofit * 0.06
ElseIf .Row = 7 Then
redProfit = baseprofit * 0.05
End …Run Code Online (Sandbox Code Playgroud)