Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-10

String with °

12 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kamen Kamen

Hello,
I have string with ? and I want to delete all symbols to ?. When I delete symbol ? returns #176. How can I delete this symbol? Exampe: s := '49?45 ';

After: delete (s, 1, 2); --> '?45 '
After: delete (s, 1, 1); or delete (s, pos ('?', s), 1); -->

#176'45 '

I want to reseive only '45 '.
Regards,
Kamen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131010/73844d0b/attachment.html>

Reply by email

Mattias Gaertner
to Kamen Kamen
Show quoted text 11 lines
Hello, I have string with ? and I want to delete all symbols to ?. When I delete symbol ? returns #176. How can I delete this symbol? Exampe: s := '49?45 '; After: delete (s, 1, 2); --> '?45 ' After: delete (s, 1, 1); or delete (s, pos ('?', s), 1); --> #176'45 ' I want to reseive only '45 '.
delete (s, pos ('?', s), length('?'));

Mattias

Reply by email

Michael Van Canneyt
to Kamen Kamen: I have string with ? and I want to delete all symbols to ?. When I delete symbol ?…
Kamen Kamen wrote
Hello, I have string with ? and I want to delete all symbols to ?. When I delete symbol ? returns #176. How can I delete this symbol?

What is the encoding of this string ? UTF8 ?

Show quoted text 6 lines
Exampe: s := '49?45 '; After: delete (s, 1, 2); --> '?45 ' After: delete (s, 1, 1); or delete (s, pos ('?', s), 1); -->? #176'45 '

Delete uses a byte count, not a char count. If your string is encoded in UTF-8, then you will probably get the behaviour you see.

To my knowledge, there is currently no routine in the RTL that does this correct.

Michael.

Reply by email

Hans-Peter Diettrich
to Kamen Kamen: I have string with ? and I want to delete all symbols to ?. When I delete symbol ?…
Show quoted text 10 lines
I have string with ? and I want to delete all symbols to ?. When I delete symbol ? returns #176. How can I delete this symbol? Exampe: s := '49?45 '; After: delete (s, 1, 2); --> '?45 ' After: delete (s, 1, 1); or delete (s, pos ('?', s), 1); --> #176'45 ' I want to reseive only '45 '.
Most probably '?' is a multi-byte UTF-8 symbol. You can declare it as a
  const Deg: UTF8string = '?';
and obtain the part past it using
   NextPos := Pos(Deg,s)+ Length(Deg);
   Tail := Copy(s, NextPos, Length(s));

When working with strings containing non-ASCII characters you should forget about Char and character (byte) based functions. Use strings instead, even for single letters, and the string based functions (Pos, StringReplace...).

DoDi

Reply by email

Mattias Gaertner
to Hans-Peter Diettrich
Show quoted text 5 lines
[...] When working with strings containing non-ASCII characters you should forget about Char and character (byte) based functions. Use strings instead, even for single letters, and the string based functions (Pos, StringReplace...).

And/or use the UTF8 functions in unit LazUtf8.

Mattias

Reply by email

Bart
to Michael Schnell
Michael Schnell wrote
As Lazarus works with UTF8, and the string functions like "pos" and "delete" count bytes rather than (visible) characters, you can't use the visible character position for these functions.

As Mattias pointed out: in this case Use Utf8Delete(). It is in LazUtf8 unit.

Bart

Reply by email

Mattias Gaertner
to Michael Schnell: As Lazarus works with UTF8, and the string functions like "pos" and "delete" count bytes…
As Lazarus works with UTF8, and the string functions like "pos" and "delete" count bytes rather than (visible) characters, you can't use the visible character position for these functions.

The "visible character position" is an amazingly complex topic. Gladfully most programmers don't need them for their daily work. You can use Delete and Pos for UTF8.

Mattias

Reply by email

Kamen Kamen

Thanks, Mattias! Now is OK.

-------- ?????????? ????? --------
??: Mattias Gaertner
???????: Re: [Lazarus] String with ?
??:
????????? ??: ?????????, 2013, ???????? 10 11:57:04 EEST

On Thu, 10 Oct 2013 11:52:24 +0300 (EEST)

Kamen Kamen > wrote 21 lines
Hello, I have string with ? and I want to delete all symbols to ?. When I delete symbol ? returns #176. How can I delete this symbol? Exampe: s := '49?45 '; After: delete (s, 1, 2); --> '?45 ' After: delete (s, 1, 1); or delete (s, pos ('?', s), 1); --> #176'45 ' I want to reseive only '45 '.
delete (s, pos ('?', s), length('?'));

Mattias

Reply by email

Mattias Gaertner
to Bart: As Mattias pointed out: in this case Use Utf8Delete(). It is in LazUtf8 unit. Bart
Show quoted text 8 lines
On 10/10/13, Michael Schnell wrote: > As Lazarus works with UTF8, and the string functions like "pos" and > "delete" count bytes rather than (visible) characters, you can't use the > visible character position for these functions. As Mattias pointed out: in this case Use Utf8Delete(). It is in LazUtf8 unit.

Note: UTF8Delete works in code points, not in visible characters. The "visible characters" depend on font and rendering engine.

Mattias

Reply by email

Kamen Kamen

Thanks, Bart! Where I can find help for

LazUtf8 unit? I was looking here: http://www.freepascal.org/docs.var with no success.

-------- ?????????? ????? --------
??: Bart
???????: Re: [Lazarus] String with ?
??: Lazarus mailing list
????????? ??: ?????????, 2013, ???????? 10 12:38:39 EEST

Michael Schnell > wrote 5 lines
As Lazarus works with UTF8, and the string functions like "pos" and "delete" count bytes rather than (visible) characters, you can't use the visible character position for these functions.

As Mattias pointed out: in this case Use Utf8Delete().

It is in LazUtf8 unit.

Bart

Reply by email

Kamen Kamen

Thanks, Mattias!

-------- ?????????? ????? --------
??: Mattias Gaertner
???????: Re: [Lazarus] String with ?
??:
????????? ??: ?????????, 2013, ???????? 10 13:24:00 EEST

On Thu, 10 Oct 2013 11:38:39 +0200

Bart > wrote 15 lines
On 10/10/13, Michael Schnell > wrote: > As Lazarus works with UTF8, and the string functions like "pos" and > "delete" count bytes rather than (visible) characters, you can't use the > visible character position for these functions. As Mattias pointed out: in this case Use Utf8Delete(). It is in LazUtf8 unit.

Note: UTF8Delete works in code points, not in visible characters.

The "visible characters" depend on font and rendering engine.

Mattias

Reply by email