當前位置:首頁 » 安卓系統 » 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 瀏覽:624
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:355
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:69
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:294
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:786
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:336
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:201
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:796
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:353
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:581