0

I can't quite figure out how to pad a message that I send. Basically.. I want to pad the message to the max 512 chars as defined in the RFC.

I understand that a message being sent by the user will contain user!user@hostname privmsg #chan (or other_user): text text text \r\n.

Thanks in advance.

1 Answers1

1

To pad a string you can use the functions ljust, center or rjust, respectively:

print "Hello, " + "world".ljust(10) + "!"
print "Hello, " + "world".center(10) + "!"
print "Hello, " + "world".rjust(10) + "!"

Output (Try it):

Hello, world     !
Hello,   world   !
Hello,      world!

All three functions have an optional second argument fillchar which lets you specify the character that is used to fill up the additional space.

Falko
  • 17,076
  • 13
  • 60
  • 105
  • Basically all I would need to do is determine original string length as X, use one of the pad functions "ljust(512-X)" ?? or something similar? I am also unsure as to how I would implement this as an xchat2 plugin/script. – Brian Shafer Aug 18 '14 at 01:33
  • As can be seen from the example, you do not need to determine ```len(X)```, since the argument ```10``` is already the total width. You should have a look into [the documentation](https://docs.python.org/2/library/stdtypes.html#string-methods) if in doubt. – Falko Aug 18 '14 at 04:59
  • Regarding the second part of your question: I have no idea! You should give a little more information about what you are trying to achieve and what code you have so far. I thought it's about strings (as the title indicates). So maybe you even open a new question to attract peoples attention that are more into xchat2. – Falko Aug 18 '14 at 05:05