TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Counting the number of characters inside of a variable.

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
elminster



Joined: 13 Jul 2009
Posts: 46

PostPosted: Wed May 31, 2017 3:09 pm    Post subject: Counting the number of characters inside of a variable. Reply with quote

I occasionally have a variable that exceeds a character limit, and I would like to break it up into more variables so that they do not exceed that limit. This does not always happen, just sometimes.

I am texting certain strings to my phone, and the email to text service ignores anything beyond the SMS limit (I believe it is 160 chars).

Would be really ideal of I could break it into as many necessary parts as needed to capture the entire string.

Thanks!
Back to top
View user's profile Send private message AIM Address
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed May 31, 2017 5:57 pm    Post subject: Reply with quote

You can use something like this, it splits the string as #list elements with a "maxlen" lenght:
Code:

#var maxlen {20};
#var test {Supercalifragilisticexpialidocious};

#format {varlen} {%L} {$test};
#if {$varlen>$maxlen}
{
    #format {test_parts} {%w} {{$test}{$maxlen}}
}


Result:
Code:

#VARIABLE {test_parts}={{1}{Supercalifragilistic}{2}{expialidocious}}


and because it's a #list you can use it's SIZE command to know how many elements you must send
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Sat Jun 17, 2017 2:19 pm    Post subject: Reply with quote

Slightly easier using %w, which does this exact thing, and also properly handles spaces.

You can grab multiple indexes in an array or table using a regular expression, so no need for complicated mechanics to parse the array.

Code:

#var input bliblablobliblablo bliblablobliblablo bliblablo;

#format output {%w} {{$input}{160}};

#foreach {$output[%*]} {tmp} {#showme $tmp}
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group