当前位置:K88软件开发文章中心编程语言非主流编程语言Apex → 文章内容

Apex - 字符串

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 16:30:40

由 youj 创建, 最后一次修改 2016-12-20 与任何其他编程语言一样,Apex中的字符串是没有字符限制的任何字符集。示例:String companyName = 'Abc International';System.debug('Value companyName variable'+companyName);字符串方法Salesforce中的String类有许多方法。 我们将看看本章中一些最重要和最常用的字符串方法。contains 包含如果给定的字符串包含所提到的子字符串,此方法将返回true。语法:public Boolean contains(String substring)示例:String myProductName1 = 'HCL';String myProductName2 = 'NAHCL';Boolean result = myProductName2.contains(myProductName1);System.debug('O/p will be true as it contains the String and Output is: '+result );equals如果给定的字符串和在方法中传递的字符串具有相同的二进制字符序列,并且它们不为空,那么此方法将返回true。 您也可以使用此方法比较SFDC记录ID。 此方法区分大小写。语法:public Boolean equals(Object string)示例:String myString1 = 'MyString';String myString2 = 'MyString';Boolean result = myString2.equals(myString1);System.debug('Value of Result will be true as they are same and Result is:'+result);equalsIgnoreCase如果字符串Compare具有与给定字符串相同的字符序列,则此方法将返回true。 但是,此方法不区分大小写。句法:public Boolean equalsIgnoreCase(String stringtoCompare)示例:下面的代码将返回true作为字符串字符和顺序是相同的,忽略大小写的敏感性。String myString1 = 'MySTRING';String myString2 = 'MyString';Boolean result = myString2.equalsIgnoreCase(myString1);System.debug('Value of Result will be true as they are same and Result is:'+result);remove 删除此方法从给定字符串中删除stringToRemove中提供的字符串。 当您想从字符串中删除某些特定字符,并且不知道要删除的字符的确切索引时,这很有用。 此方法区分大小写,如果出现相同的字符序列但是情况不同,则此方法将不起作用。语法:public String remove(String stringToRemove)示例:String myString1 = 'This Is MyString Example';String stringToRemove = 'MyString';String result = myString1.remove(stringToRemove);System.debug('Value of Result will be 'This Is Example' as we have removed the MyString and Result is :'+result);removeEndIgnoreCase此方法删除stringToRemove中从给定字符串中提取的字符串,但前提是它出现在结尾。 此方法不区分大小写。语法:public String removeEndIgnoreCase(String stringToRemove)示例:String myString1 = 'This Is MyString EXAMPLE';String stringToRemove = 'Example';String result = myString1.removeEndIgnoreCase(stringToRemove);System.debug('Value of Result will be 'This Is MyString' as we have removed the 'Example' and Result is :'+result);startWith如果给定的字符串以方法中提供的前缀开头,此方法将返回true。语法:public Boolean startsWith(String prefix)示例:String myString1 = 'This Is MyString EXAMPLE';String prefix = 'This';Boolean result = myString1.startsWith(prefix);System.debug(' This will return true as our String starts with string 'This' and the Result is :'+result);

Apex - 字符串