当前位置:首页 » 安卓系统 » android获取字符串

android获取字符串

发布时间: 2022-07-08 00:49:24

Ⅰ 如何得到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中显示出来

(1)android获取字符串扩展阅读:

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 字符串怎么获取各个字符

java中String 类有一个方法为substring(int beginIndex, int endIndex),它返回一个新字符串,它是此字符串从指定的
beginIndex处开始,一直到索引 endIndex - 1处的字符组成的新字符串。因此,该子字符串的长度为 endIndex-beginIndex


String a="a796Fb28@";

String b=a.substring(0,5);

则b返回值为a796F。

Ⅲ android 怎么获取TextView字符串的长度

如果用testSize设置汉字的大小,其值用像素表示。用 屏幕宽度的像素/汉字宽度像素就得到了所能显示文字的长度,如果出现字母和特殊符号的时候,这样计算字符串长度就不准确了。
可用下面办法获取长度:
Paint paint =
new
Paint();

paint.setTextSize(currentTextView.getTextSize());

float size =paint.measureText(currentTextView.getText().toString());

Ⅳ 如何在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 几个经常用到的字符串的截取

几个经常用到的字符串的截取
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 截取指定位置字符串

spilt()这个方法可以,,String类里面的,spilt()方法,就是专门截取字符串的,具体的就不说了,你网络它就对了。可以看到更加详细的列子

热点内容
scratch少儿编程课程 发布:2025-04-16 17:11:44 浏览:619
荣耀x10从哪里设置密码 发布:2025-04-16 17:11:43 浏览:347
java从入门到精通视频 发布:2025-04-16 17:11:43 浏览:62
php微信接口教程 发布:2025-04-16 17:07:30 浏览:288
android实现阴影 发布:2025-04-16 16:50:08 浏览:781
粉笔直播课缓存 发布:2025-04-16 16:31:21 浏览:334
机顶盒都有什么配置 发布:2025-04-16 16:24:37 浏览:197
编写手游反编译都需要学习什么 发布:2025-04-16 16:19:36 浏览:791
proteus编译文件位置 发布:2025-04-16 16:18:44 浏览:350
土压缩的本质 发布:2025-04-16 16:13:21 浏览:578