using System.Collections.Generic;
public static void Main()
string newCorrectValue =MaxLength("C/ Clara Campoamor Rodríguezííí 1",30,false);
Console.WriteLine("-----New Value------");
Console.WriteLine(newCorrectValue);
Console.WriteLine("New Data Length:{0}", newCorrectValue.Length);
Console.WriteLine("-----------");
public static string MaxLength(string data, int maxLength, bool returnAsEmpty)
var listOfIndexes = new List<Int64>();
Int16 lengthWithMultiByte = 0;
listOfIndexes.Add(index);
if ((listOfIndexes.Contains(newIndex)) && (lengthWithMultiByte < maxLength))
var tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(c.ToString());
newData = newData + System.Text.Encoding.UTF8.GetString(tempBytes);
Console.WriteLine("Data Length before trim:{0}", data.Length);
Console.WriteLine("New Data Length before trim:{0}", newData.Length);
Console.WriteLine("{0} -----> {1}", data, newData);
if (newData.Length < maxLength)
return newData.Substring(0, maxLength);