0

I have a variable whose value is "Big Apple" and that is what I am displaying on my form. I want to keep the variable value as it is but like to display just "Apple" from it. I do not want to use SubString. Just through loop somehow or any other way. Is it possible? How to do it?

$result.content = "Big Apple"
foreach($number in $result.content)
{
    $result.content "Apple"  //for display
}
3
  • 1
    Split()? If you know the format of the content (e.g. always two strings) and which part you want (e.g. second string), then you could do something like this: $result.content.split()[1] Commented Sep 18, 2019 at 21:44
  • @boxdog Thanks it works. Commented Sep 18, 2019 at 22:06
  • I posted my suggestion as an answer. Feel free to accept it :-) Commented Sep 18, 2019 at 22:17

1 Answer 1

1

If you know the format of the content (e.g. always two strings) and which part you want (e.g. second string), then you could do something like this:

$result.content.split()[1]

If you are not sure how many parts there are in the string, but always want the last one, do this:

$result.content.split()[-1]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.