Morse code (Morse Code) C # implementation

Source: Internet
Author: User
Morse code (also translated into Morse code, Morse code) is a time-pass time-broken signal codes, in different order to express different English letters, numbers and punctuation. It was invented by the American Elfid Ville in 1837. Morse code is an early form of digital communication, but it differs from modern binary codes that use only 0 and one or two states, and its codes include five kinds: points, strokes, pauses between points and strokes, short pauses between characters (between points and strokes), medium pauses between words, and long pauses between sentences.

Note that you can only use ASCII encoding 127 in the English/digital text and

Unicode is not supported but you can modify a portion of it yourself to support Unicode

Example code:

public static class Morsecode//Morse code (Interstellar traversal) {private static volatile string[,] codetable = {             {"A", ".-"}, {"B", "-..."}, {"C", "-.-."}, {"D", "-.."}, {"E", "."}, {"E", ".. -.. "}, {" F ",".. -. "}, {" G ","--. "}, {" H "," ... "}, {" I "," ... "}, {" J ",".---"}, {" K ","-.-"}, {" L ",".-.. "}, {" M ","--"}, {" N ","-. "}, {" O ","---"}, {             "P", ".--."}, {"Q", "--.-"}, {"R", ".-."}, {"S", "..."}, {"T", "-"}, {"U", ".. -"}, {" V "," ...-"}, {" W ",".--"}, {" X ","-..             -"}, {" Y ","-.--"}, {" Z ","--.. "}, {" 0 ","-----"}, {" 1 ",".----"}, {"2", "..            ---"}, {" 3 "," ...-"}, {" 4 "," ....-"}, {" 5 "," ... "}, {" 6 ","-.... "}, {"7", "--..."}, {"8", "---.."}, {"9", "----."}, {".", ".-.-.-"}, {",", "--.. --"},             {":","---..."},             {"?",".. --.."},             {"\'",".----."},             {"-","-....-"},             {"/","-.. -."},             {"(","-.--."},             {")","-.--.-"},             {"\"",".-.. -."},             {"=","-...-"},             {"+",".-.-."},             {"*","-.. -"}, {" @ ",".--.-. "}, {" {understood} "," ...-. "}, {" {ERROR} "," ... "}, {" { Invitation to transmit} ","-.-"}, {" {WAIT} ",".-... "}, {" {END of work} "," ...-.-"}, {" {ST                  Arting SIGNAL} ","-.-.-"}, {" "," \u2423 "}};             public static string Enc (String str) {int i; string ret = string.             Empty; if (str! = null && (str = str). ToUpper ()). Length > 0) foreach (char asc in STR) if ((I= Find (ASC.             ToString (), 0)) >-1) ret + = "" + codetable[i, 1];         return ret;             } public static string Dec (String str) {int i;             String[] splits; string ret = string.             Empty; if (str! = NULL && (splits = str. Split (')).  Length > 0) {foreach (string split in splits) if ((i = Find (split, 1))                 >-1) ret + = codetable[i, 0];             return ret;         } return "{#}";  } private static int Find (string str, int cols) {int i = 0, Len = codetable.length/ 2;                     Len/rank while (i < len) {if (codetable[i, cols] = = str)                 return i;             i++;             };         return-1; }     }

Using code:

String encry = Morsecode.enc ("China"); Convert China to Morse code  string decry = Morsecode.dec (encry);//convert encry to clear form
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.