當前位置:首頁 » 安卓系統 » 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()方法,就是專門截取字元串的,具體的就不說了,你網路它就對了。可以看到更加詳細的列子

熱點內容
重新編目資料庫 發布:2025-05-16 00:54:34 瀏覽:513
android語音控制 發布:2025-05-16 00:53:50 瀏覽:265
win8windows無法訪問 發布:2025-05-16 00:37:53 瀏覽:894
八種排序演算法 發布:2025-05-16 00:37:17 瀏覽:55
左旋螺紋數控編程實例 發布:2025-05-16 00:11:49 瀏覽:10
安卓游戲舊版本從哪個軟體下載 發布:2025-05-16 00:00:20 瀏覽:329
連接聚類演算法 發布:2025-05-15 23:55:09 瀏覽:978
工資演算法單休 發布:2025-05-15 23:52:30 瀏覽:819
超凡先鋒配置不行怎麼辦 發布:2025-05-15 23:27:54 瀏覽:532
win7取消加密 發布:2025-05-15 23:26:37 瀏覽:472