资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android取字符串,android 截取字符串

android 几个经常用到的字符串的截取

几个经常用到的字符串的截取

创新互联建站是由多位在大型网络公司、广告设计公司的优秀设计人员和策划人员组成的一个具有丰富经验的团队,其中包括网站策划、网页美工、网站程序员、网页设计师、平面广告设计师、网络营销人员及形象策划。承接:成都网站设计、网站制作、网站改版、网页设计制作、网站建设与维护、网络推广、数据库开发,以高性价比制作企业网站、行业门户平台等全方位的服务。

string str="123abc456";

int i=3;

1 取字符串的前i个字符

str=str.Substring(0,i); // or str=str.Remove(i,str.Length-i);

2 去掉字符串的前i个字符:

str=str.Remove(0,i); // or str=str.Substring(i);

3 从右边开始取i个字符:

str=str.Substring(str.Length-i); // or str=str.Remove(0,str.Length-i);

4 从右边开始去掉i个字符:

str=str.Substring(0,str.Length-i); // or str=str.Remove(str.Length-i,i);

5 判断字符串中是否有"abc" 有则去掉之

using System.Text.RegularExpressions;

string str = "123abc456";

string a="abc";

Regex r = new Regex(a);

Match m = r.Match(str);

if (m.Success)

{

//绿色部分与紫色部分取一种即可。

str=str.Replace(a,"");

Response.Write(str);

string str1,str2;

str1=str.Substring(0,m.Index);

str2=str.Substring(m.Index+a.Length,str.Length-a.Length-m.Index);

Response.Write(str1+str2);

}

6 如果字符串中有"abc"则替换成"ABC"

str=str.Replace("abc","ABC");

************************************************

string str="adcdef"; int indexStart = str.IndexOf("d");

int endIndex =str.IndexOf("e");

string toStr = str.SubString(indexStart,endIndex-indexStart);

c#截取字符串最后一个字符的问题!

str1.Substring(str1.LastIndexOf(",")+1)

如何得到android EditText里面的字符串

Android中有许多写法创建事件处理方式,一般会使用Android:onClick属性来指定。

举例说明:

实现摄氏温度到华氏温度的转变

1、

EditText editText1 =(EditText) findViewById (R.id.editText1)

c=Integer.parseInt(editText1.getText().toString());

用来获取editText1中的信息

2、

EditText editText2 =(EditText) findViewById (R.id.editText2);

f=(9.0*c)/5.0+32.0;

editText2.setText(String.valueOf(f));

通过editText1 获取的信息然后经过计算

将计算的结果返回editText2中然后在editText2中显示出来

扩展资料:

EditText 控件的用法

EditText 在开发中也是经常用到的控件,也是一个比较必要的组件。

它是用户跟Android应用进行数据传输的窗户。

1、android:text设置文本内容。 

2、android:textColor字体颜色。 

3、android:hint内容为空时候显示的文本。 

4、android:textColorHint为空时显示的文本的颜色。 

5、android:maxLength限制显示的文本长度,超出部分不显示。 

6、android:minLines设置文本的最小行数。 

7、android:gravity设置文本位置,如设置成“center”,文本将居中显示。 

8、android:drawableLeft在text的左边输出一个drawable,如图片。 

如何在Android中从文件中读写字符串

1、通过File获取文件

2、打开输入流,读取文件

写文件:

1、创建文件

2、打开输出流,写入文件内容

示例:

12345678910111213

读文件:String content = ""; //文件内容字符串 //通过路径/sdcard/foo.txt打开文件 File file = new File("/sdcard/foo.txt"); try { InputStream instream = new FileInputStream(file);//读取输入流 InputStreamReader inputreader = new InputStreamReader(instream);//设置流读取方式 BufferedReader buffreader = new BufferedReader(inputreader); while (( line = buffreader.readLine()) != null) { content += line + "\n";//读取的文件内容 } }catch(Exception ex){ }

写文件: File file = new File("/sdcard/foo.txt");// if(!file.exists()) file.createNewFile();//如果文件不存在,创建foo.txt try { OutputStream outstream = new FileOutputStream(file);//设置输出流 OutputStreamWriter out = new OutputStreamWriter(outstream);//设置内容输出方式 out.write("文字内容");//输出内容到文件中 out.close(); } catch (java.io.IOException e) { e.printStackTrace(); }


文章标题:android取字符串,android 截取字符串
转载注明:http://cdkjz.cn/article/dsgsghh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220