Hi Robbie. Here the code: I have placed the same issue to MSDN and got an hint and therefore the answer. Hope that helps you. Bye the way The replacement was fine as the returnString didn't contain special characters also in my project where I got the error. So I didn't post that easy search and replace stuff. But anyway. Here the solution:
namespace BTS.ClassLibrary.SendPipelines {
[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
[ComponentCategory(CategoryTypes.CATID_Any)]
[System.Runtime.InteropServices.Guid("DB8303F8-918E-4BBF-9048-E09589778D1A")]
public class TradesphereHandleSpecialCharacters : IBaseComponent, IComponentUI, IComponent {
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage msg) {
if (msg.BodyPart != null) {
Stream st = msg.BodyPart.GetOriginalDataStream();
StreamReader reader = new StreamReader(st);
MemoryStream m = new MemoryStream();
StreamWriter writer = new StreamWriter(m);
//if (sOriginalStream != null) {
try {
string body = reader.ReadToEnd();
//body = body.Replace(_FindString, _ReplaceWith);
body = ReplaceOrRemoveSpecialCharacters(body);
writer.AutoFlush = true;
writer.Write(body);
m.Position = 0;
msg.BodyPart.Data = m;
reader.Close();
return msg;
} catch (Exception ex) {
EventLog.WriteEntry("Application", "BTS.SendPipelines.TradesphereHandleSpecialCharacters :: " + ex.Message);
} // END try {
// } // END if (sOriginalStream != null) {
} // END public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage msg) {
return msg;
} // END public class TradesphereHandleSpecialCharacters : IBaseComponent, IComponentUI {
public IntPtr Icon {
get {
return new System.IntPtr();
}
} // END public IntPtr Icon {
public IEnumerator Validate(object projectSystem) {
return null;
} // END public IEnumerator Validate(object projectSystem) {
public string Description {
get {
return "Replaces or removes special characters";
}
} // END public string Description {
public string Name {
get {
return "BTS.SendPipelines.TradesphereHandleSpecialCharacters";
}
} // END public string Name {
public string Version {
get {
return "1.0.0.0";
}
} // END public string Version {
private static string ReplaceOrRemoveSpecialCharacters(string _input) {
string output = String.Empty;
string pattern = @"[äüößÄÜÖØøÆæÀÁÂÃÄÅàáâãäåÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖòóôõöÝýÿÙÚÛÜùúûüÇðÞþÐ|]";
Regex regex = new Regex(pattern);
MatchEvaluator myEvaluator = new MatchEvaluator(ReplaceMethod);
output = regex.Replace(_input, myEvaluator);
string output2 = output.Replace("\r\n","").Trim();
return output2;
} // END private string ReplaceOrRemoveSpecialCharacters(string _input){
public static string ReplaceMethod(Match m) {
switch (m.Value) {
case "ß":
return "ss";
case "ä":
return "ae";
case "ö":
return "oe";
case "ü":
return "ue";
case "Ä":
return "Ae";
case "Ö":
return "Oe";
case "Ü":
return "Ue";
case "Ø":
return "O";
case "ø":
return "O";
case "Æ":
return "A";
case "æ":
return "a";
case "À":
return "A";
case "Á":
return "A";
case "Â":
return "A";
case "Ã":
return "A";
case "Å":
return "A";
case "à":
return "a";
case "á":
return "a";
case "â":
return "a";
case "ã":
return "a";
case "å":
return "a";
case "È":
return "E";
case "É":
return "E";
case "Ê":
return "E";
case "Ë":
return "E";
case "è":
return "e";
case "é":
return "e";
case "ê":
return "e";
case "ë":
return "e";
case "Ì":
return "I";
case "Í":
return "I";
case "Î":
return "I";
case "Ï":
return "I";
case "ì":
return "i";
case "í":
return "i";
case "î":
return "i";
case "ï":
return "i";
case "Ò":
return "O";
case "Ó":
return "O";
case "Ô":
return "O";
case "Õ":
return "O";
case "ò":
return "o";
case "ó":
return "o";
case "ô":
return "o";
case "õ":
return "o";
case "Ý":
return "Y";
case "ý":
return "y";
case "ÿ":
return "y";
case "Ù":
return "U";
case "Ú":
return "U";
case "Û":
return "U";
case "ù":
return "u";
case "ú":
return "u";
case "û":
return "u";
case "Ç":
return "C";
case "ð":
return "o";
case "Þ":
return "T";
case "þ":
return "T";
case "Ð":
return "D";
case "|":
return "";
default:
return m.Value;
} // END switch (m.Value) {
} // END public string replaceMethod(Match m) {
} // END class TradesphereHandleSpecialCharacters {
} // END namespace BTS.ClassLibrary.SendPipelines {