function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TheCustomCloudTheCustomCloud 

String Theory - A simple challenge - What is the best way to reformat a string?

A little challenge,

 

I have say 100 strings in a list that are in this format: 3 to 5 numbers, a space, a name.  

Example 1: "1234 Product Name One"

Example 2: "12345 Product Name Two"

 

How do I most efficiently remove the 1234 and the space so I just have Product Name? 

 

Result 1: "Product Name One"

Result 2: "Product Name Two "

Best Answer chosen by Admin (Salesforce Developers) 
jpwagnerjpwagner

I'd do this:

 

String[] examples = ...//list of product names

 

List<String> results = new List<String>();

 

for(String example : examples){

  String result = example.substring(example.indexOf(' '));

  results.add(result);

All Answers

jpwagnerjpwagner

I'd do this:

 

String[] examples = ...//list of product names

 

List<String> results = new List<String>();

 

for(String example : examples){

  String result = example.substring(example.indexOf(' '));

  results.add(result);

This was selected as the best answer
TheCustomCloudTheCustomCloud
Works perfect! Thank you Jpwagner!