コード例 #1
0
        public string Cleanup(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException("message", nameof(message));
            }

            string text = message;

            if (LowerCase)
            {
                text = text.ToLower();
            }

            if (CleanUrl)
            {
                text = Replace(text, extractor.ExtractUrlsWithIndices(message), "URL_URL");
            }

            if (CleanCashTags)
            {
                text = Replace(text, extractor.ExtractCashtagsWithIndices(text), "INDEX_INDEX");
            }

            return(emojyCleanup.Extract(text).Cleaned);
        }
コード例 #2
0
        /// <summary>
        ///     Returns the length of the specified tweet.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public int GetTweetLength(string text)
        {
            try
            {
                text = text.Normalize(NormalizationForm.FormC);
            }
            catch (ArgumentException)
            {
            }

            int length = new StringInfo(text).LengthInTextElements;

            foreach (TweetEntity urlEntity in extractor.ExtractUrlsWithIndices(text))
            {
                // Subtract the length of the original URL
                length -= urlEntity.End - urlEntity.Start;

                // Add `ShortUrlLengthHttps` characters for URL starting with https:// Otherwise add `ShortUrlLength` characters
                length += urlEntity.Value.ToLower().StartsWith("https://") ? ShortUrlLengthHttps : ShortUrlLength;
            }

            return(length);
        }