Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: truncate string to byte count

by hippo (Chancellor)
on Feb 27, 2019 at 23:32 UTC ( #1230640=note: print w/replies, xml ) Need Help??


in reply to truncate string to byte count

say I have an utf-8 encoded string that I want to truncate to a certain number of bytes.

That's an XY Problem if ever I heard one. What are you really trying to do?

Replies are listed 'Best First'.
Re^2: truncate string to byte count
by morgon (Priest) on Feb 28, 2019 at 10:02 UTC
    It is not an XY-Problem.

    It's the actual problem at hand.

    The backgound is a program that implements a (passive) check for a monitoring system where you need to write your message to a pipe but the monitoring system imposes a byte-limit on the message.

      Sounds like it is Nagios. Can‘t you modify the output length of your checks in the database? Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re^2: truncate string to byte count
by stevieb (Canon) on Feb 27, 2019 at 23:34 UTC

    That's better than my response (very long day) ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1230640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2021-02-27 01:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?