About this question
JS:
var str = "SLA-UPsdfdsfdsfG-4HR-4ON"; var res = str.substr(-7, 3);Output: 4HR
What is the alternative for Substr in apex which is starting from end due to minus starting index.
JS:
var str = "SLA-UPsdfdsfdsfG-4HR-4ON"; var res = str.substr(-7, 3);Output: 4HR
What is the alternative for Substr in apex which is starting from end due to minus starting index.
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Hadoop Expert
Answered on Jul 12, 2021
Another alternative for Substr in apex is as follows:
You can use a combination of Right and Substring method to achieve the desired output in Apex. Below code for your reference.
String str = 'SLA-UPsdfdsfdsfG-4HR-4ON'; String res = str.right(7).substring(0, 3); System.debug('res is::'+res);The result would be 4HR for the above code. What is salesforce string class ?
The salesforce String class represents character strings. All string literals in Java programs, such as "abc" , are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. ... Because String objects are immutable they can be shared.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Big Data Hadoop interview questions, answered
Guides, tips and career advice on Big Data Hadoop from JanBask experts.
Hadoop Frequently Used Hive Commands in HQL with Examples
Top Hive Commands in HQL With Examples of the most commonly used Hadoop Hive commands for importing, exporting, and querying data…
Hadoop How to Compare Hive, Spark, Impala and Presto?
Explore the strengths and weaknesses of Presto vs Impala vs Hive vs Spark for big data processing. Learn which tool is best…
Hadoop What Is Hue? Hue Hadoop Tutorial Guide for Beginners
What is Hue? Hue Tutorial Guide for Beginner, We are covering Hue component, hadoop ecosystem, Hue features, Apache Hue Tutorial…