设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2384|回复: 8
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2274
在线时间
562 小时
注册时间
2012-5-3
帖子
86

开拓者

跳转到指定楼层
1
发表于 2015-4-16 18:31:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
[email protected](/乱七八糟/)[0]
在一段游戏代码里面发现了这么一串代码,这个是写的技能的说明。但是这个split我在f1里面搜索过,没有搜到。只有Ruby里面有,这个具体用法到底是什么啊?望解答。

Lv1.梦旅人

梦石
0
星屑
94
在线时间
648 小时
注册时间
2009-2-3
帖子
238
2
发表于 2015-4-16 20:22:36 | 只看该作者
本帖最后由 lanyaolove 于 2015-4-16 20:25 编辑

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

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
33079
在线时间
5104 小时
注册时间
2012-11-19
帖子
4878

开拓者

3
发表于 2015-4-16 20:34:35 | 只看该作者
  1. p "这个,是,简单,例子。".split(/,/) # ["这个","是","简单","例子。"]
复制代码

评分

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

查看全部评分

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

使用道具 举报

Lv1.梦旅人

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

评分

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

查看全部评分

偶是熬夜学编程的傻子
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2274
在线时间
562 小时
注册时间
2012-5-3
帖子
86

开拓者

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

好的,我去看看。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9280
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

6
发表于 2015-4-18 11:09:57 | 只看该作者
  1. [email protected](/乱七八糟/)[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
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2274
在线时间
562 小时
注册时间
2012-5-3
帖子
86

开拓者

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

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

使用道具 举报

Lv4.逐梦者 (版主)

梦石
0
星屑
9532
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

8
发表于 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", "", ""]
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2274
在线时间
562 小时
注册时间
2012-5-3
帖子
86

开拓者

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

太感谢了。好好研究
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-22 21:15

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表