• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to fetch required values from a string ?

Explorer ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

Hi ,

I need to fetch a particular value from a string,

eg:

input :

abc def def test|test2|test3

my required output should be:

test|test2|test3

How to go about this using any function or any other alternate solution.

Kindly advice !!!

Views

729

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Apr 22, 2013 Apr 22, 2013

ok, so we probably need to use a regular expression then.  Something like this perhaps:

Find: ^[^ ]*? [^ ]*? [^ ]*? (.*)$

Replace with: \1

This worked for me:

<cfset yourString = "abc def def test|test2|test3">

<cfoutput>

#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#

</cfoutput>

<br />

<cfset yourString = "abc def def test|test 2|test3">

<cfoutput>

#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#

</cfoutput>

Votes

Translate

Translate
Engaged ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

Your requirements are a little bit unclear.  But it seems to me that you just want to get the bit at the end of the string, following the last space?  You could just use listLast(), specifying a space as the delimiter.

<cfset yourString = "abc def def test|test2|test3">

<cfoutput>

#listLast(yourString, " ")#

</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

hi

actually my requirement is to exclude the string values till first three spaces and print the remaining.

ie.

input :

abc def def test|test2|test3

i need to exclude "abc def def" and print the remaning test|test2|test3

but listLast will not work for some cases like

input :

abc def def test|test 2|test3

this prints

2|test3

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

ok, so we probably need to use a regular expression then.  Something like this perhaps:

Find: ^[^ ]*? [^ ]*? [^ ]*? (.*)$

Replace with: \1

This worked for me:

<cfset yourString = "abc def def test|test2|test3">

<cfoutput>

#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#

</cfoutput>

<br />

<cfset yourString = "abc def def test|test 2|test3">

<cfoutput>

#reReplaceNoCase(yourString, "^[^ ]* [^ ]* [^ ]* (.*)$", "\1")#

</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2013 Apr 22, 2013

Copy link to clipboard

Copied

LATEST

Thanks It worked !!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation