1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Text to Full Width Latin in C#

Discussion in 'C, C++, C#' started by falkor, Jan 18, 2013.

  1. falkor

    falkor Junior Member

    Joined:
    Sep 18, 2010
    Messages:
    102
    Likes Received:
    96
    Location:
    My location is...
    Home Page:
    Does anyone know how I can take the input from textBox1 and convert it into Full Width Latin in textBox2 much like this website does using javascript:

    Code:
    http://fsymbols.com/generators/wide/
    Will to tip £ or $ for the solution!
     
  2. 45415

    45415 Junior Member

    Joined:
    Feb 5, 2009
    Messages:
    194
    Likes Received:
    92
    I found a similar site, checked its source code and found Javascript source code. The script was using a map of characters. Tried to write some code in C#, seems to be working.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace FullWidthConverter
    {
        public partial class Form1 : Form
        {
            private Dictionary<char, char> letters = new Dictionary<char, char>()
                {
                    {'\u0041', '\uff21'},
                    {'\u0042', '\uff22'},
                    {'\u0043', '\uff23'},
                    {'\u0044', '\uff24'},
                    {'\u0045', '\uff25'},
                    {'\u0046', '\uff26'},
                    {'\u0047', '\uff27'},
                    {'\u0048', '\uff28'},
                    {'\u0049', '\uff29'},
                    {'\u004a', '\uff2a'},
                    {'\u004b', '\uff2b'},
                    {'\u004c', '\uff2c'},
                    {'\u004d', '\uff2d'},
                    {'\u004e', '\uff2e'},
                    {'\u004f', '\uff2f'},
                    {'\u0050', '\uff30'},
                    {'\u0051', '\uff31'},
                    {'\u0052', '\uff32'},
                    {'\u0053', '\uff33'},
                    {'\u0054', '\uff34'},
                    {'\u0055', '\uff35'},
                    {'\u0056', '\uff36'},
                    {'\u0057', '\uff37'},
                    {'\u0058', '\uff38'},
                    {'\u0059', '\uff39'},
                    {'\u005a', '\uff3a'},
                    {'\u0061', '\uff41'},
                    {'\u0062', '\uff42'},
                    {'\u0063', '\uff43'},
                    {'\u0064', '\uff44'},
                    {'\u0065', '\uff45'},
                    {'\u0066', '\uff46'},
                    {'\u0067', '\uff47'},
                    {'\u0068', '\uff48'},
                    {'\u0069', '\uff49'},
                    {'\u006a', '\uff4a'},
                    {'\u006b', '\uff4b'},
                    {'\u006c', '\uff4c'},
                    {'\u006d', '\uff4d'},
                    {'\u006e', '\uff4e'},
                    {'\u006f', '\uff4f'},
                    {'\u0070', '\uff50'},
                    {'\u0071', '\uff51'},
                    {'\u0072', '\uff52'},
                    {'\u0073', '\uff53'},
                    {'\u0074', '\uff54'},
                    {'\u0075', '\uff55'},
                    {'\u0076', '\uff56'},
                    {'\u0077', '\uff57'},
                    {'\u0078', '\uff58'},
                    {'\u0079', '\uff59'},
                    {'\u007a', '\uff5a'}
                };
            
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                textBox2.Text = convertToFullwidth(textBox1.Text);
            }
    
            private string convertToFullwidth(string text)
            {
                string output = "";
    
                for (var i = 0; i < text.Length; i++)
                {
                    char normal = text[i];
                    try
                    {
                        char latin = letters[normal];
                        output += latin;
                    }
                    catch (KeyNotFoundException e)
                    {
                        output += normal;
                    }
                }
    
                return output;
            }
        }
    }
    
    
     
    • Thanks Thanks x 1
  3. eried

    eried Newbie

    Joined:
    Jan 17, 2013
    Messages:
    14
    Likes Received:
    10
    Location:
    Chile
    Home Page:
    Here, coded an optimized version :cool::
    Code:
    private static string getWide(string input)
    {
        return input.Aggregate("", (current, c) => current + (c > 32 ? ("&#xff" + ((byte) (c - 32)).ToString("X2") + ";") : c + ""));
    }
     
  4. Blackberry_11

    Blackberry_11 Regular Member

    Joined:
    Apr 17, 2011
    Messages:
    266
    Likes Received:
    19
    I need full code ,
    if you give permeation to recreate it then I can do it for you.