[SOLVED] Trim characters/text down?

Discussion in 'Questions' started by shabbysquire, Jan 28, 2013.

  1. shabbysquire

    shabbysquire Client

    Joined:
    Nov 25, 2012
    Messages:
    545
    Likes Received:
    26
    Hey all.

    Is is possible to trim some text that's assigned to a variable?

    I'm looking at word processing but can't find a way to trim some text down, i.e. from 100 characters to only 30.
     
  2. ZennoScript

    ZennoScript Moderator

    Joined:
    Mar 4, 2011
    Messages:
    4,388
    Likes Received:
    1,693
  3. rostonix

    rostonix Administrator Staff Member

    Joined:
    Dec 23, 2011
    Messages:
    29,051
    Likes Received:
    5,544
  4. shabbysquire

    shabbysquire Client

    Joined:
    Nov 25, 2012
    Messages:
    545
    Likes Received:
    26
    This works ok if in action word processing > substring and i put: 0 - 170. It trims anything over 170 characters ok, but if a variable has, say, 150 characters, ZP comes up with an error: Failed to process text.
     
  5. ZennoScript

    ZennoScript Moderator

    Joined:
    Mar 4, 2011
    Messages:
    4,388
    Likes Received:
    1,693
  6. shabbysquire

    shabbysquire Client

    Joined:
    Nov 25, 2012
    Messages:
    545
    Likes Received:
    26
    This has done the job. Thanks for the tip!
     
  7. Cyrix

    Cyrix Client

    Joined:
    Dec 16, 2011
    Messages:
    243
    Likes Received:
    2
    Is there a way to use C# for this like the following? I tried but it failed.

    return project.Variables["yourVariableName"].Substring(0,Math.Min(30, project.Variables["yourVariableName"].Length))
     
  8. rostonix

    rostonix Administrator Staff Member

    Joined:
    Dec 23, 2011
    Messages:
    29,051
    Likes Received:
    5,544
    Code (text):
    1. return project.Variables["yourVariableName"].Value.Substring(0,Math.Min(30, project.Variables["yourVariableName"].Value.Length)) ;
     
    KitKat21 likes this.
  9. Cyrix

    Cyrix Client

    Joined:
    Dec 16, 2011
    Messages:
    243
    Likes Received:
    2
    Thank you very much.
     
  10. KitKat21

    KitKat21 Client

    Joined:
    May 2, 2017
    Messages:
    143
    Likes Received:
    70
    Yeah, thank you! :-)
     

Пользователи просматривающие тему (Пользователей: 0, Гостей: 0)