将文本从Excel复制到文本区域时删除特殊字符 [英] Remove special characters when copy text from excel to text area

查看:166
本文介绍了将文本从Excel复制到文本区域时删除特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我有一个页面,我正在创建电子邮件内容正文,但有些客户端是从Excel工作表复制到文本区域的内容和一些特殊字符复制粘贴过程中出现没有显示在文本区域但是当我通过Web服务方法保存内容时,它抛出了错误请求的异常,我调试代码并发现一些特殊字符,如[我无法在这里粘贴来自表格的那个char]。



如何避免文本区域中的那种字符?哪个编码的字符集或属性用于避免这样的字符??????



谢谢

Imrankhan

Hello friends,

I have one page where I am creating email content body, but some clients are copied content from excel sheet to text area and some special characters are coming during copy paste which are not showing in text area but when I save the content by web service method, its throwing an exception of Bad Request, I debug the code and found that some special characters like [I am not able to paste here that char] coming from sheet.

How to avoid that kinds of character in text area? Which encoded charset or attribute to be used to avoid such a chars?

Thanks
Imrankhan

推荐答案

你好,

使用此函数

Hello,
Use this function
public static string RemoveSpecialCharacters(string str) {
   StringBuilder sb = new StringBuilder();
   foreach (char c in str) {
      if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_') {
         sb.Append(c);
      }
   }
   return sb.ToString();
}


这篇关于将文本从Excel复制到文本区域时删除特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆