按照“规则”拆分字符串
来源:互联网 发布:数据有效性什么意思 编辑:程序博客网 时间:2024/05/17 22:25
public void SetData(string text){Init();UITools.SetCachedItemHide(mItems);labstring.Clear();ParseSymbol(text);if(labstring == null || labstring.Count == 0)return;if (mGrid == null || mItem == null)return;for (int i = labstring.Count-1; i >=0; i--){}UITools.GridReposition(mGrid);}List<string> labstring = new List<string> ();public void ParseSymbol(string text){if (string.IsNullOrEmpty(text))return ;int limitHeight = 440;basFont.RequestCharactersInTexture(text, fontsize, FontStyle.Normal);CharacterInfo characterInfo;int width = 0;List<int> widths = new List<int>();for (int i = 0; i < text.Length; i++){char a = text[i];basFont.GetCharacterInfo(text[i], out characterInfo, fontsize);int advancewidth = characterInfo.advance;width += characterInfo.advance;widths.Add(width);}int idex = getNearString(widths, limitHeight);string startstring = "";string endstring = "";for (int i = 0; i < text.Length; i++){char a = text[i];if (i <= idex){startstring = startstring + a;}else{endstring = endstring + a;}}labstring.Add(startstring);if (endstring == ""){}else{ParseSymbol(endstring);}}public static int getNearString(List<int> words, int width){int top = 100000;int bottom = -100000;int topidex = 0;int bottomidex = 0;for (int i = 0; i < words.Count; i++){int a = words[i];//找到离5最近的左边最小数if (a < top && a >= width){top = a;topidex = i;continue;}//找到离5最近的右边最大数if (a > bottom && a <= width){bottom = a;bottomidex = i;continue;}}if (top == bottom){return topidex;}if ((top - width) >= (width - bottom)){return bottomidex;}else{return topidex;}}
效果如图
0 0
- 按照“规则”拆分字符串
- 按照数字将字符串拆分
- php 按照回车拆分字符串注意事项
- 将string类型的字符串按照空格拆分成多个字符串
- java按照规则进行字符串的填充
- oracle自定义函数按照某个分隔符拆分字符串
- Java 将字符串按照指定字符拆分 为List
- Java中字符串按照某个字符拆分为字符数组
- 关于C#字符串按照小括号拆分报错问题
- OJ训练题之按照指定规则合并字符串
- Linux将一串字符串按照自己的规则去排版
- 将一个字符串数组中的字母按照以下规则排列
- 按照符号拆分文件内容
- 按照标题拆分子文档
- 拆分字符串
- 字符串拆分
- 拆分字符串
- 拆分字符串
- 交换机与网桥的区别
- <Flag> 从今天开始使用CSDN做笔记啦
- betterdownload.sh: 42: betterdownload.sh: Syntax error: "(" unexpected
- Android中moveTo、lineTo、quadTo、cubicTo、arcTo详解(实例)
- CPU卡相关资料收集总结
- 按照“规则”拆分字符串
- Mysql配置文件中设置字符集编码
- 大牛胡百敬的博客
- ListView的item点击事件失效,没有响应。
- 10步搞定ubuntu 14.04下ownCloud的安装
- 数据库原理(五)--关系数据库标准语言SQL(二)
- WinPcap. 获取本地驱动设备列表
- Javascript面向对象编程一
- Hadoop2.4.1 简单的wordCount的MapReduce程序