A
A
Alex Alex2016-01-23 09:24:24
Delphi
Alex Alex, 2016-01-23 09:24:24

How to work with Delphi special characters?

♥☺☻♦♣♠•◘○ Is it possible to remove all special characters from a string, apart from replacement?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Mercury13, 2016-01-23
@Mercury13

I think your higher level task is this. Users paint their names with all sorts of pictures, the task is to remove them.
It's a little unclear which version of Delphi you're working with, but let's assume 2010+.
There, string is equivalent to UnicodeString, a 16-bit string of unlimited length controlled by Delphi's reference counting.
Unicode is very large and will continue to expand, ideally there could be 1.15 million characters. Of these, 120 thousand have already been taken.
Therefore, the best solution would be to make not a black list of characters, but a white one.
Download the Unicode character base (available somewhere on unicode.org).
We make a filter out of it according to some criteria: for example, a letter / number / sign / combining / space and the direction of writing - either from left to right, or adapting.
Also, for simplicity, we exclude characters with the code 65536+ (from additional planes, they are encoded by two WideChar).
This white list is what we use. We pass along the line and remove all unnecessary ones.

S
svd71, 2016-01-23
@svd71

It looks like you are working with wide characters of type WideString. I am not aware of such a function. Yes, and such financiality is also not required. But the following script might help.
1. Assign to an AnsiString type variable.
2. Use StringReplace() to replace all questions with an empty string.
3. Reverse transformation to Wide.

V
Vasily, 2016-01-23
@Foolleren

if there is already a string, then you can create a new string and copy character by character only those that are on the white list, then replace the entire string, so there are no special characters, and instead of replacing a character, replace the string.
if the input is in the form, then you can cut off the characters even at the stage of introduction, although formally there is also a replacement.

D
dude2012, 2016-02-10
@dude2012

unreadable characters have an ASCII code < 32 . You can get the character code using the Ord function, you can look at the rest of the characters in the ASCII table. Some of them are pseudo-graphics, but almost all of them are readable.
In short, run in a loop and add all characters with a code greater than 32. In FAR or cmd, you can type Alt + 0 on an additional keyboard (I don’t remember where the namlock is turned off or on) alt + 1, alt + 2 ... just your characters will be displayed :)
Bubi is alt + 4, the ASCII code of the character is 4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question