Platinum Partner

Add An Array Of Hash Tags To A String

This method adds an array of hash tags to a given string, as many as possible, in order. It returns a new string of up to 140 characters, unless the original string was 140 characters or longer, in which case the original string is returned. Useful for automated Twitter status updates.

def hash_tag(str, tags)
  while tags && str.length < 140 && tags.length > 0
    tag = tags.shift
    if (str.length + tag.length) < 139
      str << " \##{tag}"
    end
  end
  str
end

Example: A short string and a few short tags.

hash_tag('A short string.', ['tag1', 'tag2', 'tag3'])
=> "A short string. #tag1 #tag2 #tag3"
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}