How would you do it? I've tried making functions that deletes everything that isn't type char but as you may have guessed that didn't work too well ^^
3 replies to this topic
#1
Posted 13 February 2011 - 03:48 PM
|
|
|
#2
Posted 13 February 2011 - 04:30 PM
Well I'm not sure if it's supported, but I'd aim for a regular expression to do this. That would make this rather simple.
#3
Posted 13 February 2011 - 07:28 PM
Er, maybe something like this?
function StripNonAlpha(const AValue: string): string;
var
SrcPtr, DestPtr: PChar;
begin
SrcPtr := PChar(AValue);
SetLength(Result, Length(AValue));
DestPtr := PChar(Result);
while SrcPtr <> #0 do begin
if SrcPtr[0] in ['a'..'z', 'A'..'Z'] then begin
DestPtr[0] := SrcPtr[0];
Inc(DestPtr);
end;
Inc(SrcPtr);
end;
SetLength(Result, DestPtr - PChar(Result));
end;
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#4
Posted 14 February 2011 - 12:40 AM
Hi Enray, welcome to CodeCall!
If your string is ansistring (ascii chars), then it's very easy to do. Just walk the members of the string and see if each of them falls into this group ['0'..'9', 'a'..'z', 'A'..'Z'] (like Alex had suggested, but I think he missed the numeric part). If not, just delete the member.
It's different story if you want to support unicode string (including UTF-8) , since in unicode alphanumeric members covers huge number.
What have you came up so far?
If your string is ansistring (ascii chars), then it's very easy to do. Just walk the members of the string and see if each of them falls into this group ['0'..'9', 'a'..'z', 'A'..'Z'] (like Alex had suggested, but I think he missed the numeric part). If not, just delete the member.
It's different story if you want to support unicode string (including UTF-8) , since in unicode alphanumeric members covers huge number.
What have you came up so far?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top










