|登录 |注册

查看: 2002|回复: 3
打印 上一主题 下一主题

【请教】 string 中 detect 字

[复制链接]
bboycs
2011-8-13 12:32 AM
【c++】
solitaire 游戏指令
example command:

“move a new card to column 1”
“move a new card to stack  1

“move 1 card from column 5 to column 3”
“move 4 cards from column 3 to column 7”
  1. getline(cin,inst)

  2. if(inst == ???)
  3. {
  4. ...
  5. }
复制代码
2”

请问要怎么做才可以找到 column 和 getline 里的integer??

另外if statement要怎么打才可以include integer ??

有劳了~
Irvine1987
2011-8-13 12:56 AM
你的问题很乱勒
bboycs
2011-8-13 01:11 AM
是很难问一下- -。。

这是我必须 input the command...

your command : =>move a card from stack 6 to column 2

要如何detect这条command要我去的operation

因为有很多种command...
“move 4 cards from column 3 to column 7”
"next card"
~Zero
2011-8-16 10:05 AM
把所有的 command 可能性都列出来。找出其中能够分辨的不同点。

我想到最 general 的方法就是用 String.matches 和 regular expression。
http://download.oracle.com/javas ... String.html#matches(java.lang.String)
http://download.oracle.com/javas ... ex/Pattern.html#sum

  1. if (command.matches("move a new card to .*") { ...... }
  2. else if (command.matches("move \d* cards? from column \d* to column \d*")) { ..... }
复制代码
[/code]
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2026-1-1 03:56 AM , Processed in 0.093886 second(s), 24 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部