Comments (3)
感谢反馈,GScript
目前并没有提供 while
关键字,可直接使用 for
循环替代。
目前暂不支持 +=
语法和数组直接比较 s[i] == s[j]
,后续会逐步完善。
调整后可运行的代码:
string S = "abcdefx";
string T = "def";
int myIndex(string S,string T,int pos) {
int i = pos;
int j = 0;
byte[] s = toByteArray(S);
byte[] t = toByteArray(T);
int slen = len(s);
int tlen = len(t);
for(i <= slen && j <= tlen) {
byte si = s[i];
byte sj = s[j];
if (si == sj) {
i = i+1;
j = j+1;
}else{
i = i - j + 1;
j = 0;
}
}
if (j == tlen) {
return i - tlen;
} else {
return slen-i;
}
}
int res = myIndex(S,T,0);
println(res);
from gscript.
//enhancement
string str = "foo";
char[] ch = str.chars(); //转换为字符数组,可以通过index拿到单个字符
//or
string s = str.get(index);
from gscript.
class Strings {
string get(string str,int index) {
byte[] bs = toByteArray(str);
int idx = index;
if(idx >= len(bs)) {
return nil;
}else {
return toString(bs[idx: idx + 1]);
}
}
}
Strings s = Strings();
string foo = "foo";
string f = s.get(foo,0);
println(f); //expected f = "f";
from gscript.
Related Issues (11)
- [教程语法错误] HOT 1
- 关于数组的语法,我觉得这样更好一些 HOT 3
- [请教]有没有 `printf`? HOT 6
- [编译错误]`make build` 时报错, 提示`go-bindata` 错误 HOT 2
- 提供的二进制文件里面没有windows版本 HOT 2
- 增加语义分析/类型检查 HOT 2
- 运行时类型检查改为编译期检查
- fix int a;
- 类型系统
- 可惜已停更 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gscript.