【勘误】C# 2005 & .Net 3.0高级编程 勘误(三)
来源:互联网 发布:昆山法院淘宝网拍卖 编辑:程序博客网 时间:2024/05/17 22:24
C# 2005 & .Net 3.0高级编程
第5版 第8章集合 8.2.3显示结果
page 216、217
原文:
static void Main()
{
Find1();
Console.ReadLine();
}
很不幸,书上提供的代码是Find2,翻阅第6版的扫描版(page 198、199),问题一样,没办法,在网上找英文版,英文版的书写也是一样错误。
翻看第5版及第6版的源代码,源代码与书上的引用的字符串不一致,当然结果也不会一致。
英文版图书为CHM格式,下载地址为:http://ajax.cnrui.cn/soft/4/42/2007/20070822589.html
随书源代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Wrox.ProCSharp.RegularExpressionPlayaround
{
class MainEntryPoint
{
static void Main()
{
Find1();
Console.ReadLine();
}
static void Find1()
{
string text = @"XML has made a major impact in almost every aspect of
software development. Designed as an open, extensible, self-describing
language, it has become the standard for data and document delivery on
the web. The panoply of XML-related technologies continues to develop
at breakneck speed, to enable validation, navigation, transformation,
linking, querying, description, and messaging of data.";
string pattern = @"/bn/S*ion/b";
MatchCollection matches = Regex.Matches(text, pattern,
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace |
RegexOptions.ExplicitCapture);
WriteMatches(text, matches);
}
static void Find2()
{
string text = @"XML has made a major impact in almost every aspect of
software development. Designed as an open, extensible, self-describing
language, it has become the standard for data and document delivery on
the web. The panoply of XML-related technologies continues to develop
at breakneck speed, to enable validation, navigation, transformation,
linking, querying, description, and messaging of data.";
string pattern = @"/bn";
MatchCollection matches = Regex.Matches(text, pattern,
RegexOptions.IgnoreCase);
WriteMatches(text, matches);
}
static void WriteMatches(string text, MatchCollection matches)
{
Console.WriteLine("Original text was: /n/n" + text + "/n");
Console.WriteLine("No. of matches: " + matches.Count);
foreach (Match nextMatch in matches)
{
int Index = nextMatch.Index;
string result = nextMatch.ToString();
int charsBefore = (Index < 5) ? Index : 5;
int fromEnd = text.Length - Index - result.Length;
int charsAfter = (fromEnd < 5) ? fromEnd : 5;
int charsToDisplay = charsBefore + charsAfter + result.Length;
Console.WriteLine("Index: {0}, /tString: {1}, /t{2}",
Index, result,
text.Substring(Index - charsBefore, charsToDisplay));
}
}
}
}
- 【勘误】C# 2005 & .Net 3.0高级编程 勘误(三)
- 【勘误】C# 2005 & .Net 3.0高级编程 勘误(一)
- 【勘误】C# 2005 & .Net 3.0高级编程 勘误(二)
- 【勘误】C# 2005 & .Net 3.0高级编程 勘误(四)
- C# 2005 & .Net 3.0高级编程 勘误(五)
- unix 环境高级编程 勘误
- 《ASP.NET Web 站点高级编程》勘误 Part 1
- 《ASP.NET Web 站点高级编程》勘误 Part 2
- 《ASP.NET Web 站点高级编程》勘误 Part 3
- 勘误
- ActionScript 3.0 Cookbook勘误
- 《Beginning C# Objects》中文版勘误
- 《Beginning C# Objects》中文版勘误
- 《C#4.0 图解教程》勘误
- 《Qt Quick核心编程》勘误
- 【读书笔记】现代操作系统(第三版)勘误三
- GDAL书籍中删除数据勘误(C#语言)
- C#5.0 In A NutShell翻译勘误
- 【转】Gartner:2011十大战略技术 云计算居首
- 比Vista更震撼!真正3D桌面物理技术亮相
- mysql添加新纪录时,该记录自动添加时间列值的方法
- 不用带眼镜 东芝裸眼3D电视9个角度随便看
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关
- 【勘误】C# 2005 & .Net 3.0高级编程 勘误(三)
- php 读取rss (2)
- 好久
- Asp.net 发送邮件
- 没有烟抽的日子
- 5种最常用的开源协议
- 雕刻家
- 防止网页被图片撑开
- 绩效面谈,让员工内心不再抗拒