zoukankan      html  css  js  c++  java
  • BCB6 使用正则表达式的例子

    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    #include <regexp.h>
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    
    }
    //---------------------------------------------------------------------------
    // BCB使用正则表达式的例子
    void __fastcall TForm1::btn1Click(TObject *Sender)
    {
        // 定义正则表达式,除了 | 以外的连续字符串
        String szReg = "[^|]+";
        // 原始数据
        String szStr = "|项目代码1|项目代码2|项目代码3|项目代码4";
        // 构造正则表达式对象
        TRegexp regex(szReg.c_str());
        size_t len = 0;
        size_t pos = 0;
        while (true)
        {
            // 得到子字符串在原始字符串中起始位置pos 和 长度 len ,一开始从0位置开始找
            pos = regex.find(szStr.c_str(), &len, pos);
    
            // 如果得到一个unsigned字符的最大值,认为已经到达末尾
            if (pos == size_t(-1))
            {
                break;
            }
    
            // 显示子串
            String s = szStr.SubString(pos + 1 ,len);
            ShowMessage(s);
    
            // 移动pos
            pos += len;
        }
    }
    //---------------------------------------------------------------------------
  • 相关阅读:
    hdu 1087(LIS变形)
    poj 1088(记忆化搜索)
    hdu 1505(最大子矩阵)
    hdu 1506(好题+DP或者RMQ)
    poj 2593&&poj2479(最大两子段和)
    hdu 1003(最大子段和)
    hdu 2881(LIS变形)
    poj 1692(动态规划)
    CodeForces 626C Block Towers
    CodeForces 626B Cards
  • 原文地址:https://www.cnblogs.com/songr/p/13854847.html
Copyright © 2011-2022 走看看