帕斯卡“分割”功能 [英] Pascal 'Split' Function

查看:162
本文介绍了帕斯卡“分割”功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码帕斯卡一个小程序,我遇到了一个小问题。在其他语言中有一个名为分裂或爆炸采取由一个定义的字符打断并分割这个长字符串成几个较小的字符串,并将它们分配到一个数组的长字符串函数。
 这里是我的意思,我想做到这一点:

I am coding a little program in pascal and I have run into a small problem. In other languages there is a function named 'split' or 'explode' to take a long string that is punctuated by a defined character and splits this long string into several smaller strings and assigns them to an array. Here is what I mean, I would like to do this:

longstring:='Word1.Word2.Word3');

Split('.', longstring, OutPutVariable) ;

{ OutPutVariable[1] would be Word1}
{ OutPutVariable[2] would be Word2}
{ OutPutVariable[3] would be Word3}

这是不是真正的code,为拆不存在帕斯卡。我认为它在Delphi中存在虽然。可以anypne帮我解决这个问题?很抱歉,如果这是一个非常简单的问题,我是新来的编程

This is not real code, as the 'split' does not exist in pascal. I think it exists in Delphi though. Can anypne help me with this problem? Sorry if it is a really easy problem, I am new to programming

推荐答案

随着的TStringList 操作步骤如下:

procedure SplitText(aDelimiter: Char; const s: String; aList: TStringList);
begin
  aList.Delimiter := aDelimiter;
  aList.StrictDelimiter := True; // Spaces excluded from being a delimiter
  aList.DelimitedText := s;
end;

注: StrictDelimiter 在D2006中添加属性。

Note: The StrictDelimiter property was added in D2006.

另一种方式:

procedure SplitText(const aDelimiter,s: String; aList: TStringList);
begin
  aList.LineBreak := aDelimiter;
  aList.Text := s;
end;

可以使用多个字符作为分隔符。

Can use multiple characters as a delimiter.

这篇关于帕斯卡“分割”功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆