Reputation: 1
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
}
Upvotes: 0
Views: 267
Reputation: 8442
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]
Upvotes: 1