从字符串中删除数字 [英] Delete numbers from a String
本文介绍了从字符串中删除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何从字符串中删除数字。我尝试使用StringReplace,但我不知道如何告诉函数我要替换数字。
I'd like to know how I can delete numbers from a String. I try to use StringReplace and I don't know how to tell the function that I want to replace numbers.
这是我尝试的方法:
StringReplace(mString, [0..9], '', [rfReplaceAll, rfIgnoreCase]);
推荐答案
简单但有效。可以优化,但是应该可以从入门中获得所需的信息。
Simple but effective. Can be optimized, but should get you what you need as a start:
function RemoveNumbers(const aString: string): string;
var
C: Char;
begin
Result := '';
for C in aString do begin
if not CharInSet(C, ['0'..'9']) then
begin
Result := Result + C;
end;
end;
end;
这篇关于从字符串中删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文