字符串分割扩展 SplitEx

2016-01-29 14:03 46 1 收藏

字符串分割扩展 SplitEx,字符串分割扩展 SplitEx

【 tulaoshi.com - Delphi 】

 
该示例演示了一个字符串扩展splitex例子,文章内含源代码。



  function SplitEx(const Str {需要拆分的文章}, Delimiters {拆分关键字,回车.?!等}: string): TStringList;
  var
  ss: WideString;
  i, St: integer;
  function IsDelimiter(const Delimiters, c: string): Boolean;
  begin //判断是否为拆分关键字
  result := StrScan(PChar(Delimiters), c[1]) < nil;
  end;
  begin
  Result := TStringList.Create;
  with Result do
  begin
  Clear; Sorted := True; Duplicates := dupIgnore;
  end;
  if Length(Str) < 1 then exit;
  ss := Str; //双字符支持,纯英文可以去掉
  St := -1;
  for i := 1 to Length(ss) do
  if IsDelimiter(Delimiters, ss[i]) then
  if St < -1 then
  begin
  Result.Add(Trim(Copy(ss, St, i - St)));
  St := -1;
  end
  else
  if St = -1 then St := i;
  if St < -1 then Result.Add(Copy(ss, St, Length(Str)));
  end;

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/delphi/)

  //操作演示
  with SplitEx(Memo1.Text, ',,. ?! ' + #13#10) do
  try
  SaveToFile('c:temp_demo.txt');
  finally
  Free;
  end;

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/delphi/)


 

来源:https://www.tulaoshi.com/n/20160129/1492398.html

延伸阅读
  Dim s As String = "gtdfg123fdgdfs123dd123"         Dim c() As Char = {"1", "2", "3"}         Dim a() As String = s.Split(c)         Dim p As String     ...
标签: Web开发
去掉字符串中匹配 的字符串 代码如下: /** * 去掉字符串中匹配 的字符串 * * @author zhujie * @return String regex 要替换的内容 value 字符串 state 替换的内容变成什么 */ public static String toRegex(String regex, String value, String state) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(value); String...
Delphi中的字符串 ——摘自网络 一:各种字符串  字符串是Object Pascal所有数据类型中最有用的类型。许多函数以字符串为传递参数。由于在Delphi中字符串的定义和使用有各种方式,包括Pascal中典型的字符串(String),Delphi支持的长字符串(ANSIString),类似于C语言的字符数组(Array of Char),指向字符的...
标签: Web开发
a href="1.htm"251/a 怎么用JS把251替换为 span style='background-color: #99FF99'251/span [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
SELECT   SUBSTR (T.RPT_ID,                 INSTR (T.RPT_ID,',',1,C.LV)+ 1,                 INSTR (T.RPT_ID,',',1,C.LV + 1)- (INSTR (T.RPT_ID,',',1,C.LV)+ 1)) &n...

经验教程

997

收藏

20
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部