Discord large text generator

Python 2, 275 268 267 bytes

d=['']*256
d[48:58]='zero one two three four five six seven eight nine'.split()
d[9]=d[10]=d[32]='white_large_square'
d[65:90]=d[97:122]=map(lambda c:'regional_indicator_'+chr(c),range(97,122))
print' '.join((':%s:'%d[ord(c)])*(d[ord(c)]!='')for c in input()).strip()

It creates a large list of strings, iterates through the input string's characters and gets the string from the list using the character's ord value. Works for ascii characters only. Replaces space, tab and newline only; any other whitespace will be discarded.

It did leave whitespaces in front so I had to strip it in the end.

I also tried doing it with regex, turned out to be longer (286 bytes):

import re
print re.sub('([ \t\n])|([a-z])|(\d)',lambda m:':'+['white_large_square','regional_indicator_'+m.group(m.lastindex),'zero one two three four five six seven eight nine'.split()[(ord(m.group(m.lastindex))-68)%10]][m.lastindex-1]+': ',re.sub('[^a-z0-9 \t\n]','',input().lower()))

C#, 296 273 bytes


Data

  • Input String i The string to be converted
  • Output String The input converted

Golfed

(string i)=>{var o="";foreach(var c in i){var k=c|32;var t=k>96&&k<123?"regional_indicator_"+(char)k:char.IsWhiteSpace(c)?"white_large_square":c>47&&c<58?new[]{"zero","one","two","three","four","five","six","seven","eight","nine"}[c-48]:"";o+=t!=""?$":{t}: ":t;}return o;};

Ungolfed

( string i ) => {
   var o = "";
   
   foreach( var c in i ) {
      var k = c | 32;
      var t = k > 96 && k < 123
         ? "regional_indicator_" + (char) k
         : char.IsWhiteSpace( c )
            ? "white_large_square"
            : c > 47 && c < 58
               ? new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }[ c - 48 ]
               : "";
               
      o += t != ""
         ? $":{ t }: "
         : t;
   }
   
   return o;
};

Ungolfed readable

// Receives a string to be converted
( string i ) => {

   // Initializes a var to store the output
   var o = "";
   
   // Cycle through each char in the string
   foreach( var c in i ) {
      // Creates a temp int to check for 'a' - 'z'
      var k = c | 32;
      
      // Creates a temp string that checks if the char is a lowercase letter
      var t = k > 96 && k < 123
         // If so, "builds" a Discord letter
         ? "regional_indicator_" + (char) k
         
         // Otherwise, checks if the char is a whitespace
         : char.IsWhiteSpace( c )
            // If so, "builds" a Discord white square
            ? "white_large_square"
            
            // Otherwise, checks if the char is a digit
            : c > 47 && c < 58
               // If so, gets the digit name
               ? new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }[ c - 48 ]
               
               // Otherwise, builds nothing
               : "";
               
      // Checks if the temp string is empty or not
      o += t != ""
         // If so, format it properly -- capsulate with ':' and add a space at the end
         ? $":{ t }: "
         
         // Otherwise, add the temp string, it's empty, so won't do anything
         : t;
   }
   
   // Return the converted string
   return o;
};

Full code

using System;
using System.Collections.Generic;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, String> f = ( string i ) => {
            var o = "";
            
            foreach( var c in i ) {
               var k = c | 32;
               var t = k > 96 && k < 123
                  ? "regional_indicator_" + (char) k
                  : char.IsWhiteSpace( c )
                     ? "white_large_square"
                     : c > 47 && c < 58
                        ? new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }[ c - 48 ]
                        : "";
                        
               o += t != ""
                  ? $":{ t }: "
                  : t;
            }
            
            return o;
         };
         
         List<String>
            testCases = new List<String>() {
               "this is a test string 0123456789",
               "!?#$YAY 1234",
               "lots         of         spaces",
            };
         
         foreach( String testCase in testCases ) {
            Console.WriteLine( $" Input: {testCase}\nOutput: {f( testCase )}\n" );
         }

         Console.ReadLine();
      }
   }
}

Releases

  • v1.1 - -23 bytes - Implemented pinkfloydx33 suggestions.
  • v1.0 - 296 bytes - Initial solution.

Notes

  • None

05AB1E, 75 bytes

žK… 	
©«Ãlvyaiy’‹¬_Âì_ÿ’}ydiy“¡×€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š“#è}®yåi’„¸_…Æ_ï©’}…:ÿ:ðJ

Try it online!

Explanation

žK…<space><tab><newline>©«Ã   # remove any character that isn't in [A-Za-z0-9<whitespace>]
lv                            # loop over each character converted to lowercase
yai                           # if it is a letter
   y’‹¬_Âì_ÿ’}                # interpolate into string "regional_indicator_<letter>"
ydi                           # if it is a digit
   y“¡×€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š“#è} # extract it from a list of digits as words
®yåi                          # if it is whitespace
    ’„¸_…Æ_ï©’}               # push the string "large_white_square"
…:ÿ:                          # interpolate in string ":<emoji>:" 
    ð                         # push a space
     J                        # join stack to one string