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

How to fetch required values from a string ?

Explorer ,
Apr 22, 2013 Apr 22, 2013

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 !!!

824
Translate
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>

Translate
Engaged ,
Apr 22, 2013 Apr 22, 2013

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>

Translate
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

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

Translate
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

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>

Translate
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
LATEST

Thanks It worked !!!

Translate
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