Results 1 to 6 of 6

Thread: Subtract text from variable

  1. #1
    Private
    Join Date
    Aug 2012
    Posts
    78
    Thanks
    20
    Thanked 10 Times in 5 Posts

    Subtract text from variable

    Hey, how to subtract a piece of text from variable?

    Code:
    self.variable="1234567890";
    self.variable-="0";
    I tried but to no avail, help me someone in this thread?

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    getsubstr()

  3. #3
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    substring = getSubStr( string , startIndex , endIndex ); //if endIndex is not set, it may default to string.size

    string = "1234567890";
    substring = getSubStr( string , 0 , string.size - 1 ); //skip last char '0'
    Last edited by serthy; 10th January 2014 at 20:51. Reason: Dang, to slow ._.

  4. The Following 2 Users Say Thank You to serthy For This Useful Post:

    kung foo man (11th January 2014),Ni3ls (11th January 2014)

  5. #4
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by serthy View Post
    substring = getSubStr( string , startIndex , endIndex ); //if endIndex is not set, it may default to string.size

    string = "1234567890";
    substring = getSubStr( string , 0 , string.size - 1 ); //skip last char '0'
    Shouldn't 'string.size - 1' be 'string.size -2'? Because index start at 0 and ends in this case at 9. 'string.size - 1' won't remove any chararacter.

    Ok, i am wrong. It will return '12345678'.
    Documentation says 'Returns the substring of characters >= <start index> and < <end index>. <end index> is optional';
    Last edited by Mitch; 10th January 2014 at 21:39.

  6. The Following User Says Thank You to Mitch For This Useful Post:

    Ni3ls (11th January 2014)

  7. #5
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by Mitch View Post
    Shouldn't 'string.size - 1' be 'string.size -2'? Because index start at 0 and ends in this case at 9. 'string.size - 1' won't remove any chararacter.
    some pitfalls of codscript ^__^

  8. #6
    Private
    Join Date
    Aug 2012
    Posts
    78
    Thanks
    20
    Thanked 10 Times in 5 Posts
    Thank you serthy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •