怎样删除英文字符? ( 积分: 300 )

Z

zxin

Unregistered / Unconfirmed
GUEST, unregistred user!
在一个文本中,我想过滤掉除了中文以外的所有字符,就是点击一下Button,但是要注意中文的对齐,不能显得太乱了
这个是测试文本:
shining friends(无线青春剧当四叶草碰上剑尖时主题曲) - fiche fung mathilde chan peggy lee - TV MAGIC
作曲:陈光荣作词:anders
a little faith brightens a rainy day
小小的信念照亮那下雨天
life is difficult you can't go away
生命难困苦 你总不能逃避
don't hide yourselve in the corner
不要于躲角落
you have my place to stay
我的胸怀可让你倚靠
sorrow is gonna say goodbye
忧伤终会跟你说再见
opens up you'll see the happy sunshine
张开眼睛你会看见快乐的阳光
keep going on with your dream
继续追寻梦想
chasing tomorrow's sunrise
向着明天的太阳追赶
the spirit can never die
不会逝去的 是信念与理想
sun will shine, my friend
好朋友 太阳会闪耀
won't let you cry, my dear
谁都不会令你流泪
seeing you shed a tear make my world disappear
你的一滴眼泪都会让我的世界灰暗
you'll never be alone in darkness
在黑暗中 你永不会孤独
see my smile, my friend
好朋友 看我的笑颜
we are with you, holding hands
手牵手 我们和你一起走
you have got to believe, you are my destiny
在我宁静的心灵 你是我的信念与目标
we're meant to be your friends
我们永远都会在一起
that's what a friendship be
因为我们是朋友
 
在一个文本中,我想过滤掉除了中文以外的所有字符,就是点击一下Button,但是要注意中文的对齐,不能显得太乱了
这个是测试文本:
shining friends(无线青春剧当四叶草碰上剑尖时主题曲) - fiche fung mathilde chan peggy lee - TV MAGIC
作曲:陈光荣作词:anders
a little faith brightens a rainy day
小小的信念照亮那下雨天
life is difficult you can't go away
生命难困苦 你总不能逃避
don't hide yourselve in the corner
不要于躲角落
you have my place to stay
我的胸怀可让你倚靠
sorrow is gonna say goodbye
忧伤终会跟你说再见
opens up you'll see the happy sunshine
张开眼睛你会看见快乐的阳光
keep going on with your dream
继续追寻梦想
chasing tomorrow's sunrise
向着明天的太阳追赶
the spirit can never die
不会逝去的 是信念与理想
sun will shine, my friend
好朋友 太阳会闪耀
won't let you cry, my dear
谁都不会令你流泪
seeing you shed a tear make my world disappear
你的一滴眼泪都会让我的世界灰暗
you'll never be alone in darkness
在黑暗中 你永不会孤独
see my smile, my friend
好朋友 看我的笑颜
we are with you, holding hands
手牵手 我们和你一起走
you have got to believe, you are my destiny
在我宁静的心灵 你是我的信念与目标
we're meant to be your friends
我们永远都会在一起
that's what a friendship be
因为我们是朋友
 
是程序代码还是sql数据库
首先以字节方式打开并读取文本如果读入的字节转换成ascii码后处于a~Z之间就跳过反之复制到新的文本中至于中文对齐不太好办,不过看你的demo都挺规律的,应该不会很乱。
数据库就麻烦了,还要写存储过程判断
 
for i:= length(text)-1 downto 0 do
if ord(text)< 125 then //我忘记是不是125 反正就是最大的英文的ASCCI码
text:=0

思路就是这样.
 
for i:= length(text)-1 downto 0 do
if (ord(text)< ord('Z')) and (ord(text)> ord('a')) ) then
text:=0
 
楼上的思路可以实现,但速度有些慢了。

开是的我就不说了。
后边的是隔一行是一行英文,可以用TEXTFILE来连接文件,用readln和writeln来更改内容,这样快些
 
楼上各位的解中'、-、()和半角空格是去不掉的。下面是我的解测试过你的demo。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// 取出src中的汉字,存放到res内
procedure GetCHNText(src, res: TStrings);
var
line: string;
p: PChar;
c: Char;
i: integer;
begin
p := PChar(src.Text);
i := 0;
line := '';
c := p[0];
while c <> #0 do
begin
c := p;
if Byte(c) >= 160 then
line := line + c
else if (c = #13) and (Length(line) > 0) then
begin
res.Add(line);
line := ''
end;
inc(i);
end;
end;

//用打开文件对话框打开文本文件,读取其中的其中的汉字放到Memo1中显示,并保存到new.txt文件中
procedure TForm1.Button1Click(Sender: TObject);
var
fs: TStringList;
begin
if OpenDialog1.Execute then
begin
fs := TStringList.Create;
try
fs.LoadFromFile(OpenDialog1.FileName);
Memo1.Lines.Clear;
GetCHNText(fs, Memo1.Lines);
finally
fs.Free;
end;
end;
memo1.Lines.SaveToFile('new.txt');
end;
end.
 
1、正则表达式
2、遍历一次
 
newsmile,还是您的方法最好,非常感谢您,有时间多向您请教!
 
多人接受答案了。
 
你太客气了,问题其实挺简单的,出了那么多分搞得我都不好意思,我们共同学习!
 
顶部