`
akon405
  • 浏览: 44111 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

wps笔试题目,实现java中indexof函数

阅读更多

关于wps笔试中实现indexof方法的一种写法。

 

package com.akon;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {
	private String input;
	public int indexof(String str){
		int i=-1;
		String regex=".*?"+str;
		Pattern p=Pattern.compile(regex);
		Matcher m=p.matcher(input);
		if(m.find()){
			i=m.group().length()-str.length();	
		}
			return i;
	}
	public test(String string){
		this.input=string;
	}
	public static void main(String args[]){
		test t=new test("abcdsas23sa");
		System.out.print(t.indexof("23"));			
	}
}

 结果:7

1
3
分享到:
评论
2 楼 akon405 2012-09-29  
337240552 写道
wps待遇咋样呢

详细的我也不是很清楚,但是金山公司还不错
1 楼 337240552 2012-09-28  
wps待遇咋样呢

相关推荐

Global site tag (gtag.js) - Google Analytics