C# 截取中英文混合字符串分行显示宽度相同
来源:互联网 发布:网络歌曲软绵绵 编辑:程序博客网 时间:2024/05/21 09:22
/// <summary>
/// 截取指定长度(宽度一样)字符串,区分中英文
/// </summary>
/// <param name="str">要截取的字符串</param>
/// <param name="length">截取长度</param>
/// <returns>截取后的字符串</returns>
public static string CutStr(string str, int length)
{
if (length < 1) return str;
if (System.Text.Encoding.Default.GetByteCount(str) <= length)
{
return str;
}
else
{
byte[] txtBytes = System.Text.Encoding.Default.GetBytes(str);
byte[] newBytes = new byte[length - 4];
for (int i = 0; i < length - 4; i++)
{
newBytes[i] = txtBytes[i];
}
return System.Text.Encoding.Default.GetString(newBytes) + "... ";
}
}
/// 截取指定长度(宽度一样)字符串,区分中英文
/// </summary>
/// <param name="str">要截取的字符串</param>
/// <param name="length">截取长度</param>
/// <returns>截取后的字符串</returns>
public static string CutStr(string str, int length)
{
if (length < 1) return str;
if (System.Text.Encoding.Default.GetByteCount(str) <= length)
{
return str;
}
else
{
byte[] txtBytes = System.Text.Encoding.Default.GetBytes(str);
byte[] newBytes = new byte[length - 4];
for (int i = 0; i < length - 4; i++)
{
newBytes[i] = txtBytes[i];
}
return System.Text.Encoding.Default.GetString(newBytes) + "... ";
}
}
0 0
- C# 截取中英文混合字符串分行显示宽度相同
- C# 中英文混合字符串截取
- C#中英文混合字符串截取指定长度
- C#中英文混合字符串截取函数
- 截取中英文混合字符串
- 截取中英文混合字符串
- 中英文混合字符串截取
- 中英文混合字符串截取
- Java截取中英文混合字符串
- Java 截取中英文混合字符串
- js截取中英文混合字符串
- Cocos2dx中英文混合字符串截取
- php截取中英文混合字符串
- 字符串中英文混合前后截取
- lua截取中英文混合字符串
- Java 截取中英文混合字符串
- 用C#截取指定长度的中英文混合字符串
- 用C#截取指定长度的中英文混合字符串
- 电信11考试说明
- linux内核编译时出现“make: arm-linux-gcc:command not found!!!!!!
- iphone--常用开源库
- PHP获日期 本周一,本周日,上周一,上周日,本月最后一天,上月一日,上月最后一天
- mvc笔记
- C# 截取中英文混合字符串分行显示宽度相同
- POI工具
- 成为软件工程师之前,你必须了解这些
- PHP识别电脑还是手机访问网站
- jar文件的创建--学习笔记
- 分享企业站稳居百度首页操作细节
- POJ 3216 Prime Path(数字BFS)
- MySql源码安装过程问题
- iterator与reverse_iterator