查看: 2789|回复: 8

[已经解决] 关于字符串的问题

[复制链接]
梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

发表于 2015-4-16 18:31:49 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
description=@skill.description.split(/乱七八糟/)[0]
在一段游戏代码里面发现了这么一串代码,这个是写的技能的说明。但是这个split我在f1里面搜索过,没有搜到。只有Ruby里面有,这个具体用法到底是什么啊?望解答。
梦石
0
星屑
94
在线时间
648 小时
注册时间
2009-2-3
回帖
208
发表于 2015-4-16 20:22:36 | 显示全部楼层
本帖最后由 lanyaolove 于 2015-4-16 20:25 编辑

根据后方参数 自动分割字符串 默认是空格
回复

使用道具 举报

梦石
0
星屑
34511
在线时间
5096 小时
注册时间
2012-11-19
回帖
4715

开拓者

发表于 2015-4-16 20:34:35 | 显示全部楼层
  1. p "这个,是,简单,例子。".split(/,/) # ["这个","是","简单","例子。"]
复制代码

评分

参与人数 1星屑 +150 收起 理由
RyanBern + 150 认可答案

查看全部评分

xp vx va mv  va mz 各类型脚本/插件定制
回复

使用道具 举报

梦石
0
星屑
175
在线时间
332 小时
注册时间
2013-7-6
回帖
316
发表于 2015-4-17 08:32:31 | 显示全部楼层
建议你看看rmxp里的Regexp类与正则表达式(不保证你能看懂)
字符串的split方法的用途是把字符串对象按该方法的参数进行分割,返回分割后的数组,对原字符串没有破坏性。用来处理字符串很方便。

评分

参与人数 1星屑 +150 收起 理由
RyanBern + 150 认可答案

查看全部评分

偶是熬夜学编程的傻子
回复

使用道具 举报

梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

 楼主| 发表于 2015-4-17 21:30:18 | 显示全部楼层
wolves 发表于 2015-4-17 08:32
建议你看看rmxp里的Regexp类与正则表达式(不保证你能看懂)
字符串的split方法的用途是把字符串对象按该方 ...

好的,我去看看。
回复

使用道具 举报

梦石
0
星屑
9292
在线时间
2504 小时
注册时间
2011-5-20
回帖
14521

开拓者

发表于 2015-4-18 11:09:57 | 显示全部楼层
  1. description=@skill.description.split(/乱七八糟/)[0]
复制代码
description的值变成@skill.description里的第0个“乱七八糟”后面的字符串?
比如@skill.description是“123乱七八糟456”,那么description会变成123

评分

参与人数 1星屑 +150 收起 理由
RyanBern + 150 认可答案

查看全部评分

[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复

使用道具 举报

梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

 楼主| 发表于 2015-4-20 23:01:55 | 显示全部楼层
chd114 发表于 2015-4-18 11:09
description的值变成@skill.description里的第0个“乱七八糟”后面的字符串?
比如@skill.description是“1 ...

还是不是太懂了。这个split方法为何在rgss帮助里面搜索不到呢?这样完全不晓得如果定义的嘛!
回复

使用道具 举报

梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2015-4-21 09:02:58 | 显示全部楼层
RMXP中并没有String#split的说明,因此RMXP的帮助有很多不全面的地方,毕竟这不是Ruby的API手册。
下面引用rubydoc,应该够参考了。
#split(pattern = $;, [limit]) ⇒ Array

Divides str into substrings based on a delimiter, returning an array of these substrings.

If pattern is a String, then its contents are used as the delimiter when splitting str. If pattern is a single space, str is split on whitespace, with leading whitespace and runs of contiguous whitespace characters ignored.

If pattern is a Regexp, str is divided where the pattern matches. Whenever the pattern matches a zero-length string, str is split into individual characters.

If pattern is omitted, the value of $; is used. If $; is nil (which is the default), str is split on whitespace as if ` ' were specified.

If the limit parameter is omitted, trailing null fields are suppressed. If limit is a positive number, at most that number of fields will be returned (if limit is 1, the entire string is returned as the only entry in an array). If negative, there is no limit to the number of fields returned, and trailing null fields are not suppressed.

" now's  the time".split        #=> ["now's", "the", "time"]
" now's  the time".split(' ')   #=> ["now's", "the", "time"]
" now's  the time".split(/ /)   #=> ["", "now's", "", "the", "time"]
"1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"]
"hello".split(//)               #=> ["h", "e", "l", "l", "o"]
"hello".split(//, 3)            #=> ["h", "e", "llo"]
"hi mom".split(%r{\s*})         #=> ["h", "i", "m", "o", "m"]

"mellow yellow".split("ello")   #=> ["m", "w y", "w"]
"1,2,,3,4,,".split(',')         #=> ["1", "2", "", "3", "4"]
"1,2,,3,4,,".split(',', 4)      #=> ["1", "2", "", "3,4,,"]
"1,2,,3,4,,".split(',', -4)     #=> ["1", "2", "", "3", "4", "", ""]
回复

使用道具 举报

梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

 楼主| 发表于 2015-4-22 22:29:12 | 显示全部楼层
RyanBern 发表于 2015-4-21 09:02
RMXP中并没有String#split的说明,因此RMXP的帮助有很多不全面的地方,毕竟这不是Ruby的API手册。
下面引用 ...

太感谢了。好好研究
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部