字符串格式转换
2016-07-26 11:21
169 查看
#region Unicode转中文=================================
public static string Unic2Chinese(string str)
{
string outStr = "";
Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})");
outStr = reg.Replace(str, delegate (Match m1)
{
return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString();
});
return outStr;
}
#endregion
/// <summary>
/// 替换扩展名
/// </summary>
public static string GetUrlExtension(string urlPage, string staticExtension)
{
int indexNum = urlPage.LastIndexOf('.');
if (indexNum > 0)
{
return urlPage.Replace(urlPage.Substring(indexNum), "." + staticExtension);
}
return urlPage;
}
/// <summary>
/// 删除单个文件
/// </summary>
/// <param name="_filepath">文件相对路径</param>
public static bool DeleteFile(string _filepath)
{
if (string.IsNullOrEmpty(_filepath))
{
return false;
}
string fullpath = GetMapPath(_filepath);
if (File.Exists(fullpath))
{
File.Delete(fullpath);
return true;
}
return false;
}
/// <summary>
/// 获得当前绝对路径
/// </summary>
/// <param name="strPath">指定的路径</param>
/// <returns>绝对路径</returns>
public static string GetMapPath(string strPath)
{
if (strPath.ToLower().StartsWith("http://"))
{
return strPath;
}
if (HttpContext.Current != null)
{
return HttpContext.Current.Server.MapPath(strPath);
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\"))
{
strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
public static string Unic2Chinese(string str)
{
string outStr = "";
Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})");
outStr = reg.Replace(str, delegate (Match m1)
{
return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString();
});
return outStr;
}
#endregion
/// <summary>
/// 替换扩展名
/// </summary>
public static string GetUrlExtension(string urlPage, string staticExtension)
{
int indexNum = urlPage.LastIndexOf('.');
if (indexNum > 0)
{
return urlPage.Replace(urlPage.Substring(indexNum), "." + staticExtension);
}
return urlPage;
}
/// <summary>
/// 删除单个文件
/// </summary>
/// <param name="_filepath">文件相对路径</param>
public static bool DeleteFile(string _filepath)
{
if (string.IsNullOrEmpty(_filepath))
{
return false;
}
string fullpath = GetMapPath(_filepath);
if (File.Exists(fullpath))
{
File.Delete(fullpath);
return true;
}
return false;
}
/// <summary>
/// 获得当前绝对路径
/// </summary>
/// <param name="strPath">指定的路径</param>
/// <returns>绝对路径</returns>
public static string GetMapPath(string strPath)
{
if (strPath.ToLower().StartsWith("http://"))
{
return strPath;
}
if (HttpContext.Current != null)
{
return HttpContext.Current.Server.MapPath(strPath);
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\"))
{
strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
相关文章推荐
- log4cplus-1.2.0 编译指南(VS08)
- ios利用单例传值
- jsp 的四个作用域 :page、request、session和application的区别
- hdu 5745 dp+bitset优化
- 【HDU】-2199-Can you solve this equation?(二分)
- RPC框架碎碎念
- Java之内部类与向上转型详解(附源码)
- crm 4 注释与上传附件权限
- 医学图像常用模型评价方法
- 对Qt编译环境的认识
- ubuntu安装中文输入法
- PostgreSQL如何在一大堆字段里面排除几个字段select出来
- iframe使用总结(实战)
- 欢迎使用CSDN-markdown编辑器
- AngularJS:何时应该使用Directive、Controller、Service?
- matlab写数据到txt文件,C语言读取文件内容到数组@项目简介:基于PSS序列(频域)估计整数倍频偏
- Http/FTP多线程断点续传下载
- nginx结合活动目录认证
- 学习进度计划
- 【性能测试】性能测试学习笔记(1)