FunStrings Examples
Practical examples showing how to use FunStrings in real-world scenarios.
Basic Usage
Simple examples of basic string operations
python
1import funstrings23def main():4 """Demonstrate the basic functionality of the FunStrings package."""56 # Example string to work with7 example = "Hello, World! This is a test string."89 print("=" * 60)10 print("FunStrings Package - Basic Usage Example")11 print("=" * 60)12 print(f"Original string: '{example}'")13 print("-" * 60)1415 # Demonstrate string reversal16 print(f"Reversed: '{funstrings.reverse_string(example)}'")1718 # Demonstrate case conversion19 print(f"Uppercase: '{funstrings.to_upper(example)}'")20 print(f"Lowercase: '{funstrings.to_lower(example)}'")2122 # Demonstrate counting functions23 print(f"Vowel count: {funstrings.count_vowels(example)}")24 print(f"Consonant count: {funstrings.count_consonants(example)}")25 print(f"Word count: {funstrings.word_count(example)}")2627 # Demonstrate character sorting28 print(f"Sorted chars: '{funstrings.sort_characters(example)}'")29 print(f"Sorted (desc): '{funstrings.sort_characters(example, reverse=True)}'")3031 # Demonstrate whitespace removal32 print(f"No whitespace: '{funstrings.remove_whitespace(example)}'")3334 # Demonstrate palindrome checking35 print(f"Is palindrome: {funstrings.is_palindrome(example)}")3637if __name__ == "__main__":38 main()
Text Analysis
Analyzing text content with FunStrings
python
1import funstrings23def analyze_text(text):4 """Analyze the given text and print various statistics."""5 print(f"Text: '{text}'")6 print(f"Word count: {funstrings.word_count(text)}")7 print(f"Unique words: {funstrings.unique_words(text)}")8 print(f"Most common word: {funstrings.most_common_word(text)}")9 print(f"Word frequencies: {funstrings.get_word_frequencies(text)}")10 print(f"Longest word: {funstrings.longest_word(text)}")11 print(f"Shortest word: {funstrings.shortest_word(text)}")12 print(f"Average word length: {funstrings.average_word_length(text)}")13 print(f"Is pangram: {funstrings.is_pangram(text)}")1415# Example usage16sample_text = "The quick brown fox jumps over the lazy dog. The fox is quick and brown."17analyze_text(sample_text)
Data Cleaning
Clean and normalize text data
python
1import funstrings23def clean_text(text):4 """Clean and normalize the given text."""5 # Remove HTML tags6 text = funstrings.remove_html_tags(text)7 8 # Remove emojis9 text = funstrings.remove_emojis(text)10 11 # Expand contractions12 text = funstrings.expand_contractions(text)13 14 # Correct whitespace issues15 text = funstrings.correct_whitespace(text)16 17 # Remove special characters if needed18 # text = funstrings.remove_special_characters(text)19 20 return text2122# Example usage23dirty_text = "<p>Hello, <b>world</b>! 😊</p> This text has weird spacing and don't isn't properly formatted."24cleaned_text = clean_text(dirty_text)25print(f"Original: '{dirty_text}'")26print(f"Cleaned: '{cleaned_text}'")
Pattern Extraction
Extract patterns from text
python
1import funstrings23def extract_patterns(text):4 """Extract various patterns from the given text."""5 print(f"Text: '{text}'")6 print(f"Numbers: {funstrings.extract_numbers(text)}")7 print(f"Emails: {funstrings.extract_emails(text)}")8 print(f"URLs: {funstrings.extract_urls(text)}")9 print(f"Repeated words: {funstrings.find_repeated_words(text)}")1011# Example usage12sample_text = "Contact us at info@example.com or support@example.org. Visit our website at https://example.com. Our phone number is 123-456-7890. The example website example is repeated."13extract_patterns(sample_text)1415# Demonstrate masking sensitive data16card_number = "1234-5678-9012-3456"17masked_card = funstrings.mask_sensitive(card_number, 4)18print(f"Original card: {card_number}")19print(f"Masked card: {masked_card}")