小编B. *_*non的帖子

替换不需要的字符时,如何防止某些单词一起运行?

我想删除所有字符,如逗号、句点、引号等,这样一行:

婴儿汉斯·帕特里克以通常的方式接受了他的乳头膏,而不是通过专利瓶的工具。当他还是个孩子的时候,他的反复无常之一就是当他受到父母严厉的惩罚时,用他的小肺用尽全力尖叫。这种独特的习惯不过是使他在成熟中如此杰出的天才的预示。

...将转换为以下内容:

The infant Hans Patrick received his mammarial balm in the usual way and not through the instrumentality of a patent bottle One of his caprices when yet a child was to scream with all the force of his little lungs when he was severely chastised by his parents This singular habit was but a foreshadowing of that genius which has rendered him so eminent in his maturity
Run Code Online (Sandbox Code Playgroud)

通过这种方式,我可以在空格处拆分单个单词,并且单词末尾没有标点符号。

我正在尝试使用以下代码来做到这一点:

Regex onlyAlphanumericSpaceApostropheAndHyphen = new Regex("[^a-zA-Z0-9 '-]");
. . …
Run Code Online (Sandbox Code Playgroud)

c# regex replace trim

1
推荐指数
1
解决办法
94
查看次数

如何在 iText 7 中将一行中的一个单词加粗?

我可以使用 iText 7 设置文本粗体,如下所示:

parExecSummHeader2.Add(new Text(subj).SetBold());
Run Code Online (Sandbox Code Playgroud)

...但是当我尝试将“正常”(非粗体)文本位与粗体部分结合起来时,它不起作用。我有这个,它打印所有“常规”行(无粗体):

parExecSummHeader2.Add("Average words per sentence (the general average is 15 - 20): " + Math.Round(WordsPerSentenceInDoc, 2).ToString());
            
Run Code Online (Sandbox Code Playgroud)

...但想让计算值加粗。我尝试了这两个:

parExecSummHeader2.Add("Average words per sentence (the general average is 15 - 20): ");
parExecSummHeader2.Add(new Text(Math.Round(WordsPerSentenceInDoc, 2).ToString().SetBold()));
Run Code Online (Sandbox Code Playgroud)

...和这个:

parExecSummHeader2.Add("Average words per sentence (the general average is 15 - 20): ");
string mathval = Math.Round(WordsPerSentenceInDoc, 2).ToString();
parExecSummHeader2.Add(new Text(mathval.SetBold()));
Run Code Online (Sandbox Code Playgroud)

...但它们都不会编译,抱怨“错误 CS1061 'string' 不包含 'SetBold' 的定义,并且找不到接受类型 'string' 的第一个参数的可访问扩展方法 'SetBold'”

typography itext7

1
推荐指数
1
解决办法
6110
查看次数

正在尝试更新Android SDK

在尝试将我的SDK更新到最新版本时,安装了一些东西,但其他人没有安装.

*SDK Platform Android 4.0, API14, revision 3
Google APIs by Google Inc., Android API15 revision 1
Google APIs by Google Inc., Android API14 revision 2
Sources for Android SDK, API14, revision 1
Run Code Online (Sandbox Code Playgroud)

我得到了这个错误的消息:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-= Warning ! =-
A folder failed to be moved. On Windows this typically means that a program is uing that folder (for example Windows Explorer or your anti-virus software.)
Please momentarily deactivate your anti-virus software or close any running programs that may be accessing …
Run Code Online (Sandbox Code Playgroud)

android android-version

0
推荐指数
1
解决办法
3675
查看次数

这是确定int列表包含0的最佳方法吗?

这是确定List<int> ALogMsgTypeIntArray包含0 的最佳方法吗?

if (ALogMsgTypeIntArray.Exists(delegate(int i) { return i == 0; }))
{
    MessageBox.Show("0 exists");
}
Run Code Online (Sandbox Code Playgroud)

==========更新:

我最终这样做了:

bGetDebug = ALogMsgTypeIntList.Contains(LogParsePumpViewerConsts.LOG_MSG_TYPE_DEBUG);
bGetInfo = ALogMsgTypeIntList.Contains(LogParsePumpViewerConsts.LOG_MSG_TYPE_INFORMATION);
bGetWarning = ALogMsgTypeIntList.Contains(LogParsePumpViewerConsts.LOG_MSG_TYPE_WARNING);
bGetError = ALogMsgTypeIntList.Contains(LogParsePumpViewerConsts.LOG_MSG_TYPE_ERROR);
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
131
查看次数

为什么我的DataGridview拒绝刷新?

我正在更新表格中的一行.表的一个子集显示在DataGridView中.当我更新行时,更改不会反映在DataGridView中.即使我在提交更改后调用DataGridView.Invalidate()和DataGridView.Refresh(),我也必须关闭应用程序,重新启动并重新运行查询,然后才能看到更改.

相关代码是:

private void buttonUpdate_Click(object sender, EventArgs e)
{
    const int TICKETID_COLUMN = 0;

    String _ticketID = dataGridView1.CurrentRow.Cells[SOME_COLUMN].Value.ToString();

    UpdateRecord(_ticketID, textBoxTicketSource.Text,
                textBoxAboutSomeID.Text, textBoxCategoryID.Text, textBoxContactEmail.Text);
}

private void UpdateRecord(string ATicketID, string ATicketSource, string 
    AAboutSomeID, string ACategoryID, string AContactID)
{
    oracleConnection1.Open();
    OracleCommand ocmd = new OracleCommand();
    OracleTransaction ot;
    // Start a local transaction 
    ot = oracleConnection1.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
    // Assign transaction object for a pending local transaction 
    ocmd.Transaction = ot;
    ocmd.Connection = oracleConnection1;
    try
    {
        ocmd.CommandText = @"UPDATE ABC.CONCERTTICKETS 
                                     SET TICKETSOURCE = :p_TICKETSOURCE, 
                                     ABOUTSOMEID = …
Run Code Online (Sandbox Code Playgroud)

.net c# oracle datagridview dotconnect

0
推荐指数
1
解决办法
8088
查看次数

可以告诉字符串列表检查重复项吗?

List是否具有可以防止向其添加重复条目的属性或机制,或者每次都必须在列表中搜索它?

如果,它会更好:

List<String> AAppsToDisplay = new List<String>();
AAppsToDisplay.DuplicatesAllowed = false;
...
while (odr.Read()) 
{
  AAppsToDisplay.Add(odr.GetString(0)); 
}
Run Code Online (Sandbox Code Playgroud)

而不是必须这样做:

List<String> AAppsToDisplay = new List<String>();
. . .
String s = String.Empty;
while (odr.Read()) 
{
  s = odr.GetString(0);
  if (! AAppsToDisplay.Contains(s))
  {
    AAppsToDisplay.Add(s);  
  }
}
Run Code Online (Sandbox Code Playgroud)

.net c# generics

0
推荐指数
1
解决办法
246
查看次数

将String []转换为对象并返回String []?

我将串联的字符串放入组件的Tag属性中:

Tag = String.Format("{0};{1};{2}", AThis, AThat, ATheOtherThing);
Run Code Online (Sandbox Code Playgroud)

现在我如何解决它,因为Tag是一个对象?试着这样做:

String[] someStuff = Tag.Split(';'); 
Run Code Online (Sandbox Code Playgroud)

我得到," '对象'不包含'Split'的定义,并且没有扩展方法'Split'接受'object'类型的第一个参数可以找到

c# boxing split casting object

0
推荐指数
1
解决办法
424
查看次数

为什么找不到或打开我的文件?

我在.bin\Debug文件夹中添加了一个.txt文件,我试图打开它并像这样读取它:

using (StreamReader reader = File.OpenText("Credentials.txt")) {
    string line = null;
    do {
        line = reader.ReadLine();
        if (line.Contains("host=")) {
    . . .
Run Code Online (Sandbox Code Playgroud)

但是,虽然文件在那里,当我到达"ReadLine()"行时,它会停止在其轨道中:

System.NullReferenceException未处理Message = Object引用未设置为对象的实例.

UPDATE

我不得不将它从" do...while (line != null);" 更改为" while (! reader.EndOfStream)"

c# file-io nullreferenceexception winforms

0
推荐指数
1
解决办法
161
查看次数

这个Lambda OrderBy在我的案例中似乎是多余的 - 是吗?

我不想要任何不必要的代码,但我也希望"安全".经验观察表明,下面的OrderBy什么都不做 - 列表已经正确排序.我可以依赖于这种情况,并删除OrderBy线吗?

HashSet<int> hashSet = new HashSet<int>();
List<int> listInts = new List<int>();
using (var file = new System.IO.StreamReader(selectedFile)) {
    string line;
    int lineNum = 0;
    int Offset = (int)numericUpDownLinesOfContext.Value;
    while ((line = file.ReadLine()) != null)     {
        lineNum++;
        if (line.Contains(PlatypusToSearchFor)) {
            // This adds the lines before and after that will provide the desired context
            // (N lines from the log file before and after the searched for value)
            hashSet.UnionWith(Enumerable.Range(lineNum - Offset, Offset * 2 + 1));
        }
    }
    // …
Run Code Online (Sandbox Code Playgroud)

c# generics lambda arraylist

0
推荐指数
1
解决办法
173
查看次数

什么算法可以将文本分解为其组成单词?

我惊喜地发现使用iTextSharp从pdf文件中提取文本是多么容易.通过阅读本文,我能够使用以下简单代码将pdf文件转换为文本:

string pdfFilename = dlg.FileName;
// Show just the file name, without the path
string pdfFileNameOnly = System.IO.Path.GetFileName(pdfFilename);
lblFunnyMammalsFile.Content = pdfFileNameOnly;
string textFilename = String.Format(@"C:\Scrooge\McDuckbilledPlatypus\{0}.txt", pdfFileNameOnly);

PDFParser pdfParser = new PDFParser();
if (!pdfParser.ExtractText(pdfFilename, textFilename))
{
    MessageBox.Show("there was a boo-boo");
}
Run Code Online (Sandbox Code Playgroud)

问题是生成的文本文件包含这样的文本(即它没有空格):

IwaspleasantlysurprisedtofindhoweasyitistouseiTextSharptoextractthetextfromatextfile.
Run Code Online (Sandbox Code Playgroud)

是否有一个算法"在那里"将采取这样的文本,并最好地猜测单词中断的位置(AKA"空格")应该去哪里?

c# pdf algorithm wpf text-parsing

0
推荐指数
1
解决办法
186
查看次数