我有一个字符串列表:
List<string> _words = ExtractWords(strippedHtml);
Run Code Online (Sandbox Code Playgroud)
_words
包含1799个索引; 在每个索引中都有一个字符串.
有些字符串只包含数字,例如:
" 2"
要么 "2013"
我想删除这些字符串,所以最后List只包含字母而不是数字的字符串.
字符串就好"001hello"
但是"001"
不行,应该删除.
这是代码:
StringBuilder sb = new StringBuilder();
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
var words = Regex.Split(textBox1.Text, @"(?=(?<=[^\s])\s+\w)");
for (int i = 0; i < words.Length; i++)
{
words[i] = rgx.Replace(words[i], "");
}
Run Code Online (Sandbox Code Playgroud)
当我正在做的Regex.Split()
话包含内部字符串的字符串exmaple:
Daniel>
要么
Hello:
要么
\r\nNew
要么
hello---------------------------
我只需要得到没有所有标志的单词
所以我试图使用这个循环,但我结束说,有很多地方""
和一些地方只有------------------------
我不能在我的代码中使用它作为字符串.
我正在尝试将一些信息写入文本文件,但第二行在行之间留有空格
编码 :
private void CreateDriversList()
{
StreamWriter w = new StreamWriter(contentDirectory + "\\" + "Drivers.txt");
w.WriteLine("Module Name Display Name Driver Type Link Date");
w.WriteLine("============ ====================== ============= ======================");
//Declare, Search, and Get the Properties in Win32_SystemDriver
System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver");
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
foreach (System.Management.ManagementObject ManageObject in searcher.Get())
{
w.WriteLine(ManageObject["Name"].ToString());
w.WriteLine(" " + ManageObject["DisplayName"].ToString());
}
w.Close();
}
Run Code Online (Sandbox Code Playgroud)
一旦我添加了这一行:
w.WriteLine(" " + ManageObject["DisplayName"].ToString());
Run Code Online (Sandbox Code Playgroud)
文本文件中的结果是这样的:
Module Name Display Name Driver Type Link Date
============ ====================== ============= ======================
1394ohci
1394 …
Run Code Online (Sandbox Code Playgroud) 我不理解erorr消息以及如何解决它以及它为什么会发生.这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Threading;
namespace GatherLinks
{
class BackgroundWebCrawling
{
public string f;
int counter = 0;
List<string> WebSitesToCrawl;
int MaxSimultaneousThreads;
BackgroundWorker mainBackGroundWorker;
BackgroundWorker secondryBackGroundWorker;
WebcrawlerConfiguration webcrawlerCFG;
List<WebCrawler> webcrawlers;
int maxlevels;
public event EventHandler<BackgroundWebCrawling> ProgressEvent;
Run Code Online (Sandbox Code Playgroud)
错误发生在ProgressEvent上
错误1类型'GatherLinks.BackgroundWebCrawling'不能用作泛型类型或方法'System.EventHandler'中的类型参数'TEventArgs'.没有从'GatherLinks.BackgroundWebCrawling'到'System.EventArgs'的隐式引用转换.
我有一个用户在textBox1中输入手册的文本然后一个按钮单击将文本从textBox1复制到textBox2但在textBox2中文本看起来像一个长文本.
我希望在复制文本时,它也会复制单词之间的确切空格.
在我的新课程中,我将此代码放在顶部:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ScrambleRandomWordsTest
{
class ScrambleTextBoxText
{
private static readonly Random RandomGen = new Random();
private List<string> _words;
private List<string> _scrambledWords;
public ScrambleTextBoxText(List<string> textBoxList)
{
_words = textBoxList;
}
Run Code Online (Sandbox Code Playgroud)
然后在底部我有这个功能:
public List<string> scrambledTextBoxWords()
{
List<string> words = _scrambledWords;
return words;
}
Run Code Online (Sandbox Code Playgroud)
然后在按钮点击事件的Form1中我有:
private void BtnScrambleText_Click(object sender, EventArgs e)
{
textBox1.Enabled = false;
BtnScrambleText.Enabled = false;
textBoxWords = ExtractWords(textBox1.Text);
ScrambleTextBoxText scrmbltb = new ScrambleTextBoxText(textBoxWords);
for (int i = 0; …
Run Code Online (Sandbox Code Playgroud) 我不想禁用或使textBox只读.因为它会以灰色填充textBox.
我只想说,如果用户将尝试在textBox中键入任何内容,则不会发生任何事情.
所以我试过这个:
textBox1.Enabled = false;
Run Code Online (Sandbox Code Playgroud)
但我想让用户不能在里面键入任何内容而不是锁定或使其只读属性.
我试过这个例子:
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
它适用于字符/字符串,但我仍然可以输入数字(数字).我怎样才能避免用户也阻止输入数字?
StringBuilder sb = new StringBuilder();
var words = textBox1.Text.Split(new char[] { ' ' });
foreach (var w in words)
{
if (w == ' ')
Run Code Online (Sandbox Code Playgroud)
错误在w ==''上