火车头的Blog!

火车,沉稳、快速的前进

2007年1月27日 #

正则贪婪模式/修饰符

5贪婪模式:
前面在元字符中提到过"?"还有一个重要的作用,即"贪婪模式",什么是"贪婪模式"呢? 
比如我们要匹配以字母"a"开头字母"b"结尾的字符串,但是需要匹配的字符串在"a"后面含有很多个"b",比如"a bbbbbbbbbbbbbbbbb",那正则表达式是会匹配第一个"b"还是最后一个"b"呢?如果你使用了贪婪模式,那么会匹配到最后一个"b",反之只是匹配到第一个"b"。 
    使用贪婪模式的表达式如下: 
/a.+?b/ 
/a.+b/U 
不使用贪婪模式的如下: 
/a.+b/ 
上面使用了一个修饰符U,详见下面的部分。


修饰符:
   
在正则表达式里面的修饰符可以改变正则的很多特性,使得正则表达式更加适合你的需要(注意:修饰符对于大小写是敏感的,这意味着"e"并不等于"E")。正则表达式里面的修饰符如下: 
i :如果在修饰符中加上"i",则正则将会取消大小写敏感性,即"a"和"A" 是一样的。 
m:默认的正则开始"^"和结束"$"只是对于正则字符串如果在修饰符中加上"m",那么开始和结束将会指字符串的每一行:每一行的开头就是"^",结尾就是"$"。 
s:如果在修饰符中加入"s",那么默认的"."代表除了换行符以外的任何字符将会变成任意字符,也就是包括换行符! 
x:如果加上该修饰符,表达式中的空白字符将会被忽略,除非它已经被转义。 
e:本修饰符仅仅对于replacement有用,代表在replacement中作为PHP代码。 
A:如果使用这个修饰符,那么表达式必须是匹配的字符串中的开头部分。比如说"/a/A"匹配"abcd"。 
E:与"m"相反,如果使用这个修饰符,那么"$"将匹配绝对字符串的结尾,而不是换行符前面,默认就打开了这个模式。 
U:和问号的作用差不多,用于设置"贪婪模式"。

posted @ 2007-01-27 10:54 臨風 阅读(467) | 评论 (1)编辑

2006年10月29日 #

使用 MatchEvaluator 委托 对有汉字的整个url进行编码

采集项目中,因为经常会碰到中文的url,需要对整个url进行编码
 呵呵,代码最能说明问题,大家看吧

 System.Text.RegularExpressions.MatchEvaluator me = new System.Text.RegularExpressions.MatchEvaluator(cnUrlEncode);
            
string url = "http://community.csdn.net/中国人/Expert/中topic/5114/国5114234.xml?temp=.4305384人";
            
string urla = "http://community.csdn.net/Expert/topic/5114/5114234.xml?temp=.4305384";
            url 
= System.Text.RegularExpressions.Regex.Replace(url, "([\u4e00-\u9fa5])",me);


委托

private string cnUrlEncode(System.Text.RegularExpressions.Match m)
        
{
            
return System.Web.HttpUtility.UrlEncode(m.Groups[1].Value, System.Text.Encoding.Default);
        }

posted @ 2006-10-29 21:05 臨風 阅读(211) | 评论 (0)编辑

2006年10月28日 #

CONCAT_WS的用法

从数据库里取N个字段,然后组合到一起用“,”分割显示,起初想到用CONCAT()来处理,好是麻烦,没想到在手册里居然有提到CONCAT_WS(),非常好用。
CONCAT_WS(separator, str1, str2,...)
它是一个特殊形式的 CONCAT()。第一个参数剩余参数间的分隔符。分隔符可以是与剩余参数一样的字符串。如果分隔符是 NULL,返回值也将为 NULL。这个函数会跳过分隔符参数后的任何 NULL 和空字符串。分隔符将被加到被连接的字符串之间
简单例子如下:

mysql> SELECT CONCAT_WS(",","First name","Second name","Last Name");
       -> 'First name,Second name,Last Name'
mysql> SELECT CONCAT_WS(",","First name",NULL,"Last Name");
       -> 'First name,Last Name'

posted @ 2006-10-28 14:17 臨風 阅读(434) | 评论 (0)编辑

2006年10月27日 #

C#写的一段解析 CSV 文件的代码 选择自 redv 的 Blog

     摘要: 我们经常将Excel格式的文件保存为csv格式以方便上传和修改,可是当数据中包含逗号和双引号的时候Excel会把该字段用双引号括住并把数据中的"改为"",usingSystem;/**//***TheCommaSeparatedValue(CSV)FileFormat:http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm*描述:解析CSV格式的文... 阅读全文

posted @ 2006-10-27 14:14 臨風 阅读(206) | 评论 (0)编辑

2006年10月23日 #

盗链-真实地址嗅探

无聊之作,呵呵,发现对一些大的下载站及一些bt站的测试效果良好,只使用于以http方式下载的站点,ftp尚待研究

得到当前下载文件的url的真实文件地址:http://www.locoy.com/geturl/

posted @ 2006-10-23 12:57 臨風 阅读(354) | 评论 (0)编辑

本地MD5 SHA-1 函数 的JS实现

刚刚一段代码由于考虑用户体验要用js实现,但要传隐秘信息到服务器验证,找到该函数,测试成功,不支持中文, 但对通常的密码加密已足够


使用方法
<script type="text/javascript" src="md5.js"></script>


<script type="text/javascript" >
  hash = hex_md5("input string");
</script>


官方网站:http://pajhome.org.uk/crypt/md5/

个人认为的好处:
    1、减少服务器在md5加密的负担
    2、这样传输过程的安全也得到加强,使用JS可以得到更好的客户体验

 

md5.js下载

sha-1.js下载

posted @ 2006-10-23 12:54 臨風 阅读(91) | 评论 (0)编辑

2006年10月18日 #

The Atalasoft OCR engine

Introduction

At Atalasoft, we’re excited to unveil the newest addition to our product line, Atalasoft OCR. This suite of objects, now available, provides interfacing to OCR engines in a way that makes integration into your .NET application a snap.

In the classes provided, we offer the best of all possible worlds: a multilayered approach to exposing engine capabilities that gets up and running quickly, yet also allows you to get down to the nitty gritty details that are most important to you.

When using Atalasoft OCR engine in its most basic way, most of the work is in managing the user interface and not the OCR engine.

The following snippet of C# code demonstrates how to convert a set of image files into a single plain text file.

static void Main(string[] args)
{
    
// create and initialize the engine
    ExperVisionEngine engine = new ExperVisionEngine(nullnull);
    engine.Initialize();
     
    
// select a file or set of files
    OpenImageFileDialog openDialog = new OpenImageFileDialog();
    openDialog.Multiselect 
= true;
    
if (openDialog.ShowDialog() == DialogResult.OK) 
    
{
        SaveFileDialog saveFileDialog 
= new SaveFileDialog();
        saveFileDialog.Filter 
= "Text (*.txt)|*.txt";
        
if (saveFileDialog.ShowDialog() != DialogResult.OK)
            
return;
        
try 
        
{
            
// translate into a plain text file
            engine.Translate(
                
new FileSystemImageSource(openDialog.FileNames, true),
                
"text/plain", saveFileDialog.FileName);
        }

        
catch (OcrException err) 
        
{
            System.Console.WriteLine(
"Error in OCR: " + err.Message);
        }

    }

    engine.ShutDown();
}

As you can see, the interfacing is simple. You may also notice that the main use of the engine is the Translate method, which will takes a set of images and writes them to a file (or stream) using the given MIME type as the output format. By using the MIME standard to describe output file types, it is easy to ask the engine what output types it can support as well as to augment or replace them!

The OcrEngine maintains a collection of objects that implement an interface called ITranslator. When you request that a set of images are to be translated to an output file format, the engine will select a translator that matches the mime type.

If your task requires you to generate output in a particular format, it is short work to create your own object to translate the recognized text and images into the format that you need. You can add your new translator or take away from the engine’s translator collection as you see fit. You can even bypass the translator selection process entirely and simply supply the translator that you want to use.

OCR Engine Events

Through the familiar .NET event mechanism, you can get hooked into every step of document processing, allowing you to finely control how your images are handled. For example, you can request notification during the stage when an image is preprocessed to make it more palatable for the OCR engine, letting you alter what the engine will use for recognition.

In the following C# code snippet, you can see how to hook in your own code to do image preprocessing:

static void Main(string[] args)
{
    
// create and initialize the engine
    ExperVisionEngine engine = new ExperVisionEngine(nullnull);
    engine.Initialize();

    engine.PagePreprocessing 
+=
        
new OcrPagePreprocessingEventHandler(engine_PagePreprocessing);
}


private static void engine_PagePreprocessing(
    
object sender, OcrPagePreprocessingEventArgs e)
{
    
// override all options
    e.OptionsOut = 0;

    AtalaImage imageBW;
    
// convert to black and white, if needed
    if (e.ImageIn.PixelFormat != PixelFormat.Pixel1bppIndexed)
        imageBW 
= e.ImageIn.GetChangedPixelFormat(
                                 PixelFormat.Pixel1bppIndexed);
    
else
        imageBW 
= e.ImageIn;

    
// Deskew the image
    AutoDeskewCommand deskew = new AutoDeskewCommand();
    AtalaImage imageDeskewed 
= deskew.ApplyToImage(imageBW);
    
if (imageBW != imageDeskewed && imageBW != e.ImageIn)
        imageBW.Dispose();

    
// Hand back to the engine
    e.ImageOut = imageDeskewed;
}

As you can see, the amount of work to get hooked in is small, letting you concentrate on the task: processing the image in the way that you want.

The Atalasoft OCR objects let you hook into image processing, image segmentation, and output page construction. There are also events to let you track progress of the engine on a page as well as throughout an entire document. This lets you show your users what they need to know.

Contact Atalasoft directly for more details, or download a 30 day trial of our OCR engine today.

posted @ 2006-10-18 17:15 臨風 阅读(141) | 评论 (0)编辑

给TreeList的根和子节点弹出不同的右键菜单

好象没几个人用dev的treelist,好早就想实现这个效果,经过一个多小时的摸索,终于找到了实现方法

定义两个不同的popup contentMenu
在mouse_down事件中处理
private void JobTree_MouseDown(object sender, MouseEventArgs e)
        
{
            
if (e.Button == MouseButtons.Right)
            
{
                DevExpress.XtraTreeList.TreeListHitInfo hInfo 
= this.JobTree.CalcHitInfo(new Point(e.X, e.Y));
                
if (hInfo.HitInfoType == DevExpress.XtraTreeList.HitInfoType.Cell) //在单元格上右击了
                {
                    
if(hInfo.Node.RootNode.Id==hInfo.Node.Id) //说明是根节点 站点
                        this.barManager1.SetPopupContextMenu(this.JobTree, this.popupSite);
                    
else  //任务
                        this.barManager1.SetPopupContextMenu(this.JobTree, this.popupJob);
                }

                
            }

        }


posted @ 2006-10-18 00:02 臨風 阅读(283) | 评论 (2)编辑

2006年10月16日 #

ASCII码对照表[备忘]

     摘要: ASCII码表    信息在计算机上是用二进制表示的,这种表示法让人理解就很困难。因此计算机上都配有输入和输出设备,这些设备的主要目的就是,以一种人类可阅读的形式将信息在这些设备上显示出来供人阅读理解。为保证人类和设备,设备和计算机之间能进行正确的信息交换,人们编制的统一的信息交换代码,这就是ASCII码表,它的全称是“美国信息交换标准代码”。   八进制 十六进制 十进制... 阅读全文

posted @ 2006-10-16 10:12 臨風 阅读(11230) | 评论 (1)编辑

2006年10月2日 #

input和select表单合二为一

<input style="width:100px;height:20px;" value=" -------- " onkeydown="if(event.keyCode==13)saveUinList(value)" onkeypress="return(event.keyCode>=48&&event.keyCode<=57)" id="textUin" onclick="value=''">
<span style="position:absolute;margin:1px 1px 1px -6px">
<select style="margin-left:-102px;width:120px;" id="uinSelector" onchange="document.getElementById('textUin').value=value;saveUinList(value)">
<option selected> -------- </option>
<option value="Hello World">Hello Word</option>
</select>
</span> 
onkeypress="return(event.keyCode>=48&&event.keyCode<=57)" ASCII码 48-57表示只接受数字输入
在input和select表单里当然你可以disabled任何一个以禁用它
试了下,好象在 firefox里表现不是很好~

posted @ 2006-10-02 17:22 臨風 阅读(230) | 评论 (0)编辑

导航

统计信息

与我联系

搜索

 

常用链接

留言簿

我参加的小组

我参与的团队

随笔分类

随笔档案

相册

学习类

友情连接

娱乐类

最新评论

阅读排行榜

评论排行榜