美文网首页
Salesforce基础 - Apex字符串

Salesforce基础 - Apex字符串

作者: Salesforce开发者 | 来源:发表于2022-01-17 18:35 被阅读0次

1. public String abbreviate(Integer maxWidth)
如果当前 String 长度超过指定的长度,则附加省略号; 否则,返回原始的不带省略号的 String。maxWidth 参数的最小值是4

String s = 'Hello Maximillian';
String s2 = s.abbreviate(8);
System.debug(LoggingLevel.INFO, '*** s2: ' + s2);

2. public String abbreviate(Integer maxWidth, Integer offset)
从指定的字符偏移量 offset 开始,返回长度为指定的长度 maxWidth的缩写版String。如果在这些位置删除了字符,则返回的 String 在开头和结尾都添加了省略号。

String s = 'Hello Maximillian';
// Start at M
String s2 = s.abbreviate(9,6);
System.debug(LoggingLevel.INFO, '*** s2: ' + s2);

3. public String capitalize()
如果第一个字符是字母,则将第一个字母转化为大写字母,其余不变。

String s = 'hello maximillian';
String s2 = s.capitalize();
System.debug(LoggingLevel.INFO, '*** s2: ' + s2);

4. public Integer charAt(Integer index)
返回指定索引处字符的值。

String s = 'abcd';
Integer i = s.charAt(1);
System.debug(LoggingLevel.INFO, '*** i: ' + i);

5. public Boolean contains(String substring)
当且仅当调用该方法的 String 包含子字符串中指定的字符序列时返回 true。

String s = 'abcd';
String s2 = 'ab';
System.debug(LoggingLevel.INFO, '*** s.contains(s2): ' + s.contains(s2));

6. public Boolean containsAny(String inputString)(String substring)
如果当前 String 包含指定 String 中的任何字符,则返回 true; 否则返回 false。

String s = 'hello';
Boolean b1 = s.containsAny('hx');
Boolean b2 = s.containsAny('x');
System.debug(LoggingLevel.INFO, '*** b1: ' + b1);
System.debug(LoggingLevel.INFO, '*** b2: ' + b2);

7. public Boolean containsIgnoreCase(String substring)
如果当前 String 包含指定的字符序列而不考虑大小写,则返回 true; 否则返回 false。

String s = 'hello';
String s2 = 'H';
Boolean b1 = s.containsIgnoreCase(s2);
System.debug(LoggingLevel.INFO, '*** b1: ' + b1);

相关文章

  • Salesforce基础 - Apex字符串

    1. public String abbreviate(Integer maxWidth)如果当前 String ...

  • Salesforce基础 - 认识Apex

    什么是Apex? Apex是一种强类型的面向对象程序设计语言,它允许开发者在 Salesforce 服务器上执行流...

  • Salesforce基础 - Apex变量

    变量 变量使用 java 风格的语法声明。例如: 和 Java 一样,多个变量可以在一个语句中声明和初始化,使用逗...

  • Salesforce基础 - Apex常量

    常量 常量是指在程序的整个运行过程中值保持不变的量。常量使用 final 关键字来定义。使用 final 关键字意...

  • Salesforce基础 - Apex枚举

    枚举 枚举是一种抽象数据类型,每个值都采用您指定的一组有限标识符中的一个。枚举通常用于定义一组没有数字顺序的可能值...

  • 一款Salesforce测试工具: Apex Test Kit

    这里给大家介绍一款Salesforce测试数据生成工具Apex Test Kit。 每个Salesforce开发者...

  • Apex 企业设计模式

    FFLIB 是一个免费的框架,对 Apex 进行了扩展。它的结构实现了 Salesforce 推荐的Apex 企业...

  • Salesforce基础 - Apex数据类型

    数据类型 在 Apex 中,所有变量和表达式都有一个数据类型,例如 sObject、primitive 或 enu...

  • 从网络服务生成Apex类

    使用WSDL2Apex从网络服务生成Apex类 如果某个网络服务被定义在WSDL文件中,而Salesforce必须...

  • Apex简介

    Apex特点 Salesforce为开发者提供了Apex语言。它是一种语法上类似于Java的编程语言,有以下特点:...

网友评论

      本文标题:Salesforce基础 - Apex字符串

      本文链接:https://www.haomeiwen.com/subject/mknchrtx.html