1.字符串串联(String Concatenation)
var q =
from c in db.Customers
select new
{
c.CustomerID,
Location = c.City + ", " + c.Country
};
语句描述:这个例子使用+运算符在形成经计算得出的客户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
{
c.ContactName,
SpacePos = c.ContactName.IndexOf(" ")
};
语句描述:这个例子使用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
{
LastName = e.LastName.ToUpper(),
e.FirstName
};
语句描述:这个例子使用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
{
s.CompanyName,
Country = s.Country
.Replace("UK", "United Kingdom")
.Replace("USA", "United States of America")
};
语句描述:这个例子使用 Replace 方法返回 Country 字段中UK 被替换为 United Kingdom 以及USA 被替换为 United States of America 的供应商信息。
相关推荐
String类方法使用例子
C++中常用的string类方法C++中常用的string类方法C++中常用的string类方法C++中常用的string类方法C++中常用的string类方法C++中常用的string类方法C++中常用的string类方法C++中常用的string类方法C++中常用的...
主要介绍了C#中String类常用方法,较为详细的汇总了String类中的常用方法,对于深入掌握C#字符串操作有着很好的学习借鉴价值,需要的朋友可以参考下
string类发方法总结,是毕姥爷总结的经典之作。
Java中经常用到的String类方法。这些都是比较常用的。欢迎下载!
Scala语言的字符串类型封装的方法总结。具有大多数的String字符串方法名及其描述
以下是一些常用的string类方法: 1. 构造函数: • string(): 创建一个空的字符串。 ◦ string(const char* str): 用一个C风格字符串来初始化一个新的字符串。 ◦ string(size_t n, char c): 创建一个由n个字符c...
以下是对java中的string类方法进行了详细的分析介绍。需要的朋友可以过来参考下
C++ stl中重要容器string类的构造方法与基本概念和一些有用的字符串操作
对话框式的输入和输出,可以提供较好的界面处理。能通过弹出一个标准对话框,来提示用户。可以通过这个性质来实现具有对话框显示效果的数据输入和输出。
string类 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)...
介绍java中String类的方法,String类实例的创造
常用String类方法 文章目录常用String类方法字符串常量池1.charAt方法2.concat方法3.contains方法4.contains方法5.contentEquals(CharSequence cs)方法6.contentEquals(StringBuffer sb)方法7.endwith和starts...
java中String类的intern、split方法的详细讲解。
C++重写String类C++重写String类C++重写String类C++重写String类
字符串类扩展String类方法的应用程序
string类常用函数 包括各种方法 c++ c语言
简单总结可以下Java中String类中的常用方法
java基础String类选择题练习题,文档包含了答案与分析,适合学习用,本文档仅仅用于学习分享,不得用于商业用途