String類方法彙總

2021-06-16 06:53:35 字數 2812 閱讀 8361

1.字串串聯(string concatenation)

var q =

from c in db.customers

select new

; 語句描述:這個例子使用+運算子在形成經計算得出的客戶location值過程中將字串欄位和字串串聯在一起。

2.string.length

var q =

from p in db.products

where p.productname.length < 10

select p;

語句描述:這個例子使用length屬性查詢名稱短於10個字元的所有產品。

3.string.contains(substring)

var q =

from c in db.customers

where c.contactname.contains("anders")

select c;

語句描述:這個例子使用contains方法查詢所有其聯絡人姓名中包含「anders」的客戶。

4.string.indexof(substring)

var q =

from c in db.customers

select new

; 語句描述:這個例子使用indexof方法查詢每個客戶聯絡人姓名中出現第乙個空格的位置。

5.string.startswith(prefix)

var q =

from c in db.customers

where c.contactname.startswith("maria")

select c;

語句描述:這個例子使用startswith方法查詢聯絡人姓名以「maria」開頭的客戶。

6.string.endswith(suffix)

var q =

from c in db.customers

where c.contactname.endswith("anders")

select c;

語句描述:這個例子使用endswith方法查詢聯絡人姓名以「anders」結尾的客戶。

7.string.substring(start)

var q =

from p in db.products

select p.productname.substring(3);

語句描述:這個例子使用substring方法返回產品名稱中從第四個字母開始的部分。

8.string.substring(start, length)

var q =

from e in db.employees

where e.homephone.substring(6, 3) == "555"

select e;

語句描述:這個例子使用substring方法查詢家庭**號碼第七位到第九位是「555」的雇員。

9.string.toupper()

var q =

from e in db.employees

select new

; 語句描述:這個例子使用toupper方法返回姓氏已轉換為大寫的雇員姓名。

10.string.tolower()

var q =

from c in db.categories

select c.categoryname.tolower();

語句描述:這個例子使用tolower方法返回已轉換為小寫的類別名稱。

11.string.trim()

var q =

from e in db.employees

select e.homephone.substring(0, 5).trim();

語句描述:這個例子使用trim方法返回雇員家庭**號碼的前五位,並移除前導和尾隨空格。

12.string.insert(pos, str)

var q =

from e in db.employees

where e.homephone.substring(4, 1) == ")"

select e.homephone.insert(5, ":");

語句描述:這個例子使用insert方法返回第五位為 ) 的雇員**號碼的序列,並在 ) 後面插入乙個 :。

13.string.remove(start)

var q =

from e in db.employees

where e.homephone.substring(4, 1) == ")"

select e.homephone.remove(9);

語句描述:這個例子使用remove方法返回第五位為 ) 的雇員**號碼的序列,並移除從第十個字元開始的所有字元。

14.string.remove(start, length)

var q =

from e in db.employees

where e.homephone.substring(4, 1) == ")"

select e.homephone.remove(0, 6);

語句描述:這個例子使用remove方法返回第五位為 ) 的雇員**號碼的序列,並移除前六個字元。

15.string.replace(find, replace)

var q =

from s in db.suppliers

select new

; 語句描述:這個例子使用 replace 方法返回 country 欄位中uk 被替換為 united kingdom 以及usa 被替換為 united states of america 的**商資訊。

String型別常用方法彙總

字串的操作在開發過程中使用的比較多,以下是經常用到的一些方法 string demostring ceshibaixiaosheng 判斷字串是否包含 false system.out.println demostring.contains t 字串相加 也可以使用 string dsg demos...

string類常見函式彙總 一

語言 c 標頭檔案 include 函式 1.string.begin 和string.end begin 返回指向字串第乙個字元的迭代器。end 返回字串的結束字元,不是字串的最後乙個字元,如果要輸出最後乙個需對其進行 1操作 2.string.length length 返回字串的長度 例如 1...

String類常用彙總(二)

一.getbytes 返回字串的 byte 型別陣列。getbytes 返回乙個字串的byte型別陣列 byte a str.getbytes for byte b a 二.length 返回字串長度 system.out.println str.length 三.tolowercase 將字串轉成...