/// <summary> /// Gets the closest matches (by edit distance) from a dictionary of terms. /// </summary> public static IList <Match> GetClosestMatches(IEnumerable <string> dictionary, string term, int maxEditDistance, bool caseSensitive, bool firstLetterMustMatch) { if (dictionary == null) { throw new ArgumentNullException("dictionary"); } if (string.IsNullOrEmpty(term)) { throw new ArgumentException("The term must be specified.", "term"); } var matches = new List <Match>(); TextInfo textInfo = (caseSensitive ? null : CultureInfo.InvariantCulture.TextInfo); foreach (string candidate in dictionary) { // Check the first letter, if requested. if (firstLetterMustMatch) { bool firstLetterMatches; if (caseSensitive) { firstLetterMatches = (candidate[0] == term[0]); } else { firstLetterMatches = (textInfo.ToUpper(candidate[0]) == textInfo.ToUpper(term[0])); } if (!firstLetterMatches) { continue; } } // Check the distance. int distance; if (caseSensitive) { distance = GetEditDistanceCaseSensitive(term, candidate); } else { distance = GetEditDistance(term, candidate, textInfo); } if (distance <= maxEditDistance) { matches.Add(new Match(candidate, distance)); } } matches.Sort(CompareMatches); return(matches); }
/// <summary> /// Performs the conversion of "the Cat RAN" into "The Cat Ran" - as quickly as possible. /// </summary> public static string ToPascalSentence(string input) { if (string.IsNullOrEmpty(input)) { return(input); } TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo; int length = input.Length; StringBuilder stringBuilder = new StringBuilder(textInfo.ToLower(input), length); stringBuilder[0] = textInfo.ToUpper(input[0]); int index = input.IndexOf(' ', 0, length - 1); while (index != -1) { int nextCharIndex = index + 1; stringBuilder[nextCharIndex] = textInfo.ToUpper(input[nextCharIndex]); index = input.IndexOf(' ', nextCharIndex, length - index - 2); } return(stringBuilder.ToString()); }
static void Main(string[] args) { string output = ""; string txt; txt = Interaction.InputBox("...", "Введіть текст: ", ".капец."); TextInfo ti = CultureInfo.CurrentCulture.TextInfo; char[] arr = txt.ToCharArray(); arr[0] = ti.ToUpper(arr[0]); for (int i = 0; i < arr.Length - 1; i++) { if (arr[i] == ' ') { arr[i + 1] = ti.ToUpper(arr[i + 1]); } } foreach (char j in arr) { output += j; } MessageBox.Show($"Вхідний рядок: {txt}\nОброблений рядок: {output}", "Результат", MessageBoxButtons.OK); }
public Form4(string category, int id, string extension) { _extension = extension; InitializeComponent(); _import = new Import(id); _import.setstate += new Import.CallbackEventHandler(setstate); CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; Text = "Import " + textInfo.ToUpper(_extension) + " documents (" + category + ")"; label1.Text = textInfo.ToUpper(_extension) + " Files"; }
private static Func <string, string> GetCaseChange(TextInfo info, string text) { if (info.ToLower(text) == text) { return((txt) => info.ToTitleCase(txt)); } else if (info.ToUpper(text) == text) { return((txt) => info.ToLower(txt)); } else { return((txt) => info.ToUpper(txt)); } }
/// <summary> /// Convert text so that the first letter of each word is capitalized /// </summary> /// <param name="InString"></param> /// <returns></returns> public static string TitleCase(string InString) { if (InString == null) { return(null); } //Start with a standard current UI culture title case string TextInfo CurText = CultureInfo.CurrentUICulture.TextInfo; //Run our RegEx tests to determine whether we have Mc/Mac, salutations or roman numerals (based on http://www.codeproject.com/KB/string/ProperCaseFormatProvider.aspx) String McAndMac = @"^(ma?c)(?!s[ead]$)((.+))$"; String RomanNumerals = @"^((?=[MDCLXVI])((M{0,3})((C[DM])|(D?C{0,3}))?((X[LC])|(L?XX{0,2})|L)?((I[VX])|(V?(II{0,2}))|V)?)),?$"; //Now, run through each of our words, and handle accordingly List <string> OutStrings = new List <string>(); foreach (String Word in InString.ToLower().Split(' ')) { if (Regex.IsMatch(Word, RomanNumerals, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) { OutStrings.Add(CurText.ToUpper(Word)); } else if (Regex.IsMatch(Word, McAndMac, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)) { Match MatchedToken = Regex.Match(Word, McAndMac, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); OutStrings.Add(MatchedToken.Groups[1].Value.Substring(0, 1).ToUpperInvariant() + MatchedToken.Groups[1].Value.Substring(1).ToLowerInvariant() + MatchedToken.Groups[2].Value.Substring(0, 1).ToUpperInvariant() + MatchedToken.Groups[2].Value.Substring(1).ToLowerInvariant()); } else { OutStrings.Add(CurText.ToTitleCase(Word)); } } return(String.Join(" ", OutStrings.ToArray())); }
private bool IsMisspelled(string word) { return(_grammarEngine.Spell(word) || _grammarEngine.Spell(_textInfo.ToLower(word)) || _grammarEngine.Spell(_textInfo.ToUpper(word)) || _grammarEngine.Spell(_textInfo.ToTitleCase(word))); }
public void GestionarPesos(object sender, DirectEventArgs e) { try { GridStudents.Hidden = true; winDetails.Hidden = false; Session["GRUP_NOMBRE"] = Convert.ToString(e.ExtraParams["GRUP_NOMBRE"]); Session["CODIGO"] = Convert.ToInt32(e.ExtraParams["CODIGO"]); string temp = myTI.ToUpper(e.ExtraParams["CURS_NOMBRE"]); if (temp.Equals("SEMINARIOS DE PROFUNDIZACIÓN")) { cmbxModulo.Hidden = false; controllerGrupo.codigo = Convert.ToInt32(Session["CODIGO"]); stModulo.DataSource = ctrlModulo.ConsultarModulos(controllerGrupo); stModulo.DataBind(); stModulo.DataBind(); } else { cmbxModulo.Hidden = true; } winDetails.Title = Convert.ToString(Session["GRUP_NOMBRE"]); controllerNota.grup_Id = Convert.ToInt32(Session["CODIGO"]); dtNotesGroup = controllerNota.ConsultarPesosAcademicos(controllerNota); stPesos.DataSource = dtNotesGroup; stPesos.DataBind(); RowSelectionModel sm = this.GridAssignedGroups.GetSelectionModel() as RowSelectionModel; sm.ClearSelection(); } catch { } }
private static void TextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { var key = dependencyObject as Key; if (key != null) { var value = dependencyPropertyChangedEventArgs.NewValue as string; //Depending on parametrized case, change the value if (value != null) { TextInfo textInfo = Settings.Default.UiLanguage.ToCultureInfo().TextInfo; //If Case is specifically set, use it, otherwise, use setting value switch (key.Case == Case.Settings ? Settings.Default.KeyCase : key.Case) { case Case.Upper: value = textInfo.ToUpper(value); break; case Case.Lower: value = textInfo.ToLower(value); break; case Case.Title: //Must be lowercased first because ToTitleCase consider uppercased string as abreviations value = textInfo.ToTitleCase(textInfo.ToLower(value)); break; } } key.ShiftDownText = value; key.ShiftUpText = value; } }
public ObjectGeneric[,] Movimiento(ObjectGeneric[,] Dungeon, int x, int y, int size) { char Mov = Console.ReadKey().KeyChar; TextInfo ti = CultureInfo.CurrentCulture.TextInfo; Mov = ti.ToUpper(Mov); if (comprobar(Mov, size - 1, x, y, Dungeon)) { switch (Mov) { case 'W': Dungeon[x - 1, y] = Dungeon[x, y]; Dungeon[x, y] = new ObjectsNulls(' '); break; case 'A': Dungeon[x, y - 1] = Dungeon[x, y]; Dungeon[x, y] = new ObjectsNulls(' '); break; case 'S': Dungeon[x + 1, y] = Dungeon[x, y]; Dungeon[x, y] = new ObjectsNulls(' '); break; case 'D': Dungeon[x, y + 1] = Dungeon[x, y]; Dungeon[x, y] = new ObjectsNulls(' '); break; } } return(Dungeon); }
public static string MakeInitCap(StringSlice s, TextInfo textInfo) { #if DEBUG if (textInfo == null) { throw new ArgumentNullException(nameof(textInfo)); } #endif if (s.Length == 0) { return(string.Empty); } var actualFirstLetter = s.First(); var expectedFirstLetter = textInfo.ToUpper(actualFirstLetter); if (expectedFirstLetter == actualFirstLetter) { return(s.ToString()); } if (s.Length == 1) { return(expectedFirstLetter.ToString()); } var builder = StringBuilderPool.Get(s); builder[0] = expectedFirstLetter; return(StringBuilderPool.GetStringAndReturn(builder)); }
protected override void OnTextChanged(EventArgs e) { int currentpos = base.SelectionStart; TextInfo ti = CultureInfo.CurrentCulture.TextInfo; if (TextTransform == TextDecoration.Capitalize) { base.Text = ti.ToTitleCase(base.Text); } else if (TextTransform == TextDecoration.Lowercase) { base.Text = ti.ToLower(base.Text); } else if (TextTransform == TextDecoration.Uppercase) { base.Text = ti.ToUpper(base.Text); } else { base.Text = base.Text; } base.SelectionStart = currentpos; base.SelectionLength = 0; base.OnTextChanged(e); }
/// <summary> /// Upper case a string. /// </summary> /// <param name="input">The input string to upper case.</param> /// <returns>Returns the upper case version of the string.</returns> public string UpperCase(string input) { CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; return(textInfo.ToUpper(input)); }
private void dtg_CellEndEdit(object sender, DataGridViewCellEventArgs e) { TextInfo myTextInfo = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo; if (cmbExam.Text.Contains("TERM")) { this.MaximumMarks = 100; if (dtg.Columns[e.ColumnIndex].ValueType.Name.ToString() == "String") { string st = string.Empty; st = Convert.ToString(dtg.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); dtg.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = myTextInfo.ToUpper(st); } else { if (Convert.ToDecimal(dtg.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) <= this.MaximumMarks) { if (Convert.ToInt32(cmbClass.SelectedValue) <= 110) { dtg.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = dtg.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; } } else { MessageBox.Show("Please Fill Valide Marks."); dtg.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0; } } } }
public string getPseudoBraile() { string[] arrayText = this.text.Split(' '); for (int i = 0; i < arrayText.Length; i++) { if (Regex.IsMatch(arrayText[i], @"\d")) { arrayText[i] = 'Ʃ' + arrayText[i]; continue; } CultureInfo cultureInfo = CultureInfo.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; if (arrayText[i] == textInfo.ToUpper(arrayText[i])) { arrayText[i] = "ƱƱ" + arrayText[i].ToLower(); continue; } if (arrayText[i] == textInfo.ToTitleCase(arrayText[i])) { arrayText[i] = 'Ʊ' + arrayText[i].ToLower(); continue; } } return(String.Join(" ", arrayText)); }
public static string encrypt(int key, string word) { char[] alphabet = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; word = textInfo.ToUpper(word); string newWord = ""; foreach (char c in word) { int i = Array.IndexOf(alphabet, c); if (i == 25) { newWord += alphabet[(i - 25) + (key - 1)]; } else { newWord += alphabet[i + key]; } } return(newWord); }
private void OnMouseEnter(object sender, EventArgs e) { PlaySound("ui_move"); Control control = sender as Control; control.ForeColor = hoverColour; control.Text = textInfo.ToUpper(control.Text); }
/// <summary> /// Converts a string to UPPER-CASE and trims whites space /// </summary> public static string UpperCase(this string value) { if (value.HasNoValue()) { return(value); } return(txt.ToUpper(value.Trim())); }
public static string toUpperCase(string sString) { //Get the culture property of the thread. CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; //Create TextInfo object. TextInfo textInfo = cultureInfo.TextInfo; return(textInfo.ToUpper(sString)); }
//unsafe public Annotation(char* term, int start, int len, int sourcePos, int sourceLen) // : this(Intern(term + start, len), sourcePos, sourceLen) //{ //} public Annotation(string term, int sourcePos, int sourceLen) { // Bug 8336 - the system word-breaker (called by CiWordBreaker) sometimes converts uppercase // words to lowercase, so convert to uppercase again here. Term = TextInfo.ToUpper(term); SourcePos = sourcePos; SourceLen = sourceLen; }
//Below function handles what occurs when the "Domain:" Combobox is changed by the user. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Object lMac = comboBox1.SelectedItem; if ((lMac.ToString() == Environment.MachineName)) { this.comboBox2.Items.Clear(); SelectQuery query = new SelectQuery("Win32_UserAccount", "Domain='" + Environment.MachineName + "'"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); foreach (ManagementObject envVar in searcher.Get()) { // MessageBox.Show(envVar["Name"].ToString()); String Disabled = (envVar["Disabled"].ToString()); if (Disabled == "False") { this.comboBox2.Items.Add(envVar["Name"].ToString()); // this.comboBox2.DropDownHeight = this.comboBox2.ItemHeight * (this.comboBox2.Items.Count + 1); this.comboBox2.DropDownStyle = ComboBoxStyle.DropDownList; } } } else { try { this.comboBox2.Items.Clear(); // this.comboBox2.DropDownHeight = this.comboBox2.ItemHeight; this.comboBox2.DropDownStyle = ComboBoxStyle.DropDown; String domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; TextInfo ti = CultureInfo.CurrentCulture.TextInfo; domain = ti.ToUpper(domain); String registryKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey)) { foreach (String subkeyName in key.GetSubKeyNames()) { try { string SIDs = (key.OpenSubKey(subkeyName).ToString().Split('\\')[6]); string Users = (new SecurityIdentifier(SIDs).Translate(typeof(NTAccount)).ToString()); // MessageBox.Show((Users.Split('\\')[0]) + " " + (domain.Split('.')[0])); if ((Users.Split('\\')[0]) == (domain.Split('.')[0])) { this.comboBox2.Items.Add(Users.Split('\\')[1]); } } catch { } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public static string ToCurrencyInWords(this decimal Number) { String words = ""; try { if (Number == 0) { return(""); } string[] Nums = string.Format("{0:0.00}", Number).Split('.'); int number1 = int.Parse(Nums[0]); int number2 = int.Parse(Nums[1]); words = string.Format("{0}{1}{2}", CurrencyToWordPrefix, number1.ToWords(), CurrencyToWordSuffix); if (number2 > 0) { words = string.Format("{0} AND {1}{2}{3}", words, DecimalToWordPrefix ?? "", number2.ToWords(), DecimalToWordSuffix ?? ""); } if (IsDisplayWithOnlyOnSuffix) { words = string.Format("{0} Only", words); } CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; if (CurrencyCaseSensitive == 0) { return(textInfo.ToLower(words)); } else if (CurrencyCaseSensitive == 1) { return(textInfo.ToUpper(words)); } else if (CurrencyCaseSensitive == 2) { return(textInfo.ToTitleCase(words.ToLower())); } else { return(words); } } catch (Exception ex) { } return(words); }
static void Main(string[] args) { string mystr = "This is a test!"; CultureInfo cultureinfo = new CultureInfo(4, true); TextInfo myTextinfo = cultureinfo.TextInfo; Console.WriteLine("ANSICodePage : " + myTextinfo.ANSICodePage); Console.WriteLine("ListSeparator : " + myTextinfo.ListSeparator); Console.WriteLine("ToLower : " + myTextinfo.ToLower(mystr)); Console.WriteLine("ToUpper : " + myTextinfo.ToUpper(mystr)); Console.WriteLine("ToTitleCase : " + myTextinfo.ToTitleCase(mystr)); }
public Form1() { this.FormBorderStyle = FormBorderStyle.FixedSingle; this.MaximumSize = new Size(273, 162); this.StartPosition = FormStartPosition.CenterScreen; this.MaximizeBox = false; InitializeComponent(); //Computer, if you're on a domain, put the name in a string called "domain". String domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName; //Below task is capitalizing and recreating the "String domain" variable we made just above. This is done because //Windows makes any domain in the login screen fully capitalized, we want to mimic that as closely as possible //to avoid confusion (Cause people be dumb). { TextInfo ti = CultureInfo.CurrentCulture.TextInfo; domain = ti.ToUpper(domain); } //Here we're checking if that domain variable is actually empty, if so we're simply going to be putting the local //machine into the first "Domain:" Combobox index since this is the only option. if (string.IsNullOrEmpty(domain)) { this.comboBox1.Items.Insert(0, Environment.MachineName); this.comboBox1.Items.Insert(1, Environment.MachineName); // this.comboBox1.Enabled = false; this.comboBox1.SelectedIndex = 0; this.comboBox1.SelectedIndex = 1; this.comboBox1.BackColor = Color.White; } else //Machine has been found to be on a domain. So we do something different: { //Add domain in the first combobox bsox index and trim the top-level domain (IE .Com) from the second level domain. // First 0 indicates the combobox index number (0 is first), domain.split indicates we want to divide this string //using "." as the demarcation. [0] indicates that we want to use in this combobox index, only the first portion //found in the split (0 is first). this.comboBox1.Items.Insert(0, domain.Split('.')[0]); //For the second combobox index (The 1) we indicate that we want to use the local machine name, this is used as //secondary because the assumption is this application would be used primarily in a networked domain setting. this.comboBox1.Items.Insert(1, Environment.MachineName); } //This line says that when the application loads, the default "Domain:" combobox selection to show to the user is //the first index of that combobox (for reasons outlined above). this.comboBox1.SelectedIndex = 0; //This line makes the "User:" Combobox active for input or selection. Again working on the assumption that the //Network domain we defaulted to will be used and now the user simply wants to get along with the task of choosing //What user we'll be selecting. //ActiveControl = comboBox2; }
public Address Format(Address address) { if (address == null) { return(address); } foreach (PropertyInfo property in address.GetType().GetProperties()) { string value = property.GetValue(address)?.ToString()?.Trim() ?? ""; if (!string.IsNullOrEmpty(value)) { string formatted = ""; switch (property.Name) { case nameof(Address.Zip): case nameof(Address.Plus4): formatted = value; break; case nameof(Address.State): formatted = TextInfo.ToUpper(value); break; case nameof(Address.Street): case nameof(Address.AdditionalLine1): case nameof(Address.AdditionalLine2): formatted = FormatStreet(value); break; case nameof(Address.City): default: formatted = TextInfo.ToTitleCase(value); break; } property.SetValue(address, formatted); } } return(address); }
private void GirthDBH2_Toggled(object sender, ToggledEventArgs e) { CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; string a = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Girth").Split('(')[0]; string b = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Diameter").Split(' ')[0]; labbott.Text = (GirthDBH2.IsToggled ? a : textInfo.ToUpper(a)) + "/" + (GirthDBH2.IsToggled ? textInfo.ToUpper(b) : b); if (DetailsList.IsVisible) { List <SelectableData> TreeTails = new List <SelectableData>(); ObservableCollection <SelectableData> TreeOrig = (ObservableCollection <SelectableData>)DetailsList.ItemsSource; foreach (SelectableData g in TreeOrig) { g.GirthDiam(GirthDBH2.IsToggled); } DetailsList.ItemsSource = null; DetailsList.ItemsSource = TreeOrig; // int hold = pickPlotOne.SelectedIndex; // pickPlotOne.SelectedIndex = -1; // pickPlotOne.SelectedIndex = hold; } if (LogList.IsVisible && LogList.ItemsSource != null) { ObservableCollection <DetailsGraph2> deets = (ObservableCollection <DetailsGraph2>)LogList.ItemsSource; ObservableCollection <DetailsGraph2> deets2 = new ObservableCollection <DetailsGraph2>(); foreach (DetailsGraph2 answer in deets) { SortedList <double, double> brack = answer.brack; double[,] result = answer.result; int i = answer.resultrow; if (result[i, 0] == -1) { //answer.label = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("TooSmall"); } else if (result[i, 0] == brack.Count - 1) { answer.label = (Math.Round(brack.ElementAt((int)result[i, 0]).Key *(GirthDBH2.IsToggled ? 1 / Math.PI : 1), 2) + "cm" + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("OrLarger")); } else { answer.label = (Math.Round(brack.ElementAt((int)result[i, 0]).Key *(GirthDBH2.IsToggled ? 1 / Math.PI:1), 2) + "-" + Math.Round(brack.ElementAt((int)result[i, 0] + 1).Key *(GirthDBH2.IsToggled ? 1 / Math.PI : 1), 2) + "cm"); } deets2.Add(answer); } LogList.ItemsSource = null; LogList.ItemsSource = deets2; LogList.IsVisible = true; } }
public static string MakeAllCap(string s, TextInfo textInfo) { #if DEBUG if (s == null) { throw new ArgumentNullException(nameof(s)); } if (textInfo == null) { throw new ArgumentNullException(nameof(textInfo)); } #endif return(textInfo.ToUpper(s)); }
private string Recase(string text, int casing) { if (casing == Lowercase) { return(info.ToLower(text)); } if (casing == Uppercase) { return(info.ToUpper(text)); } return(info.ToTitleCase(text)); }
protected void txtCurrencyName_TextChanged(object sender, EventArgs e) { try { CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; string CurrencyCode = textInfo.ToUpper(txtCurrencyName.Text); txtCurrencySymbol.Text = getCurrencySymbol(CurrencyCode); } catch (Exception ex) { this.lblMessage.Text = ex.Message.ToString(); this.messagePanel.BackColor = Color.Red; } }
public static string StringToTitleCase(this string input) { if (String.IsNullOrWhiteSpace(input)) { return(""); } TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo; string result = input.Trim(); result = textInfo.ToUpper(result[0]) + result.Substring(1); return(result); }