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

Getting high and low number in a string

Explorer ,
Jul 29, 2009 Jul 29, 2009

Copy link to clipboard

Copied

Hi

I have the following

<cfset thelist = "1,5,8,11,22,76,6,143,147">

How do i get the highest and lowest number out of that string?

Thanking you in advance for your help!

Regards

Delon

TOPICS
Advanced techniques

Views

1.2K

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

Valorous Hero , Jul 29, 2009 Jul 29, 2009

Use the very well named ListToArray() function .. and definitely bookmark the online documentation 😉  The functions by category view is invaluable.

http://livedocs.adobe.com/coldfusion/8/functions-pt0_13.html

Votes

Translate

Translate
Valorous Hero ,
Jul 29, 2009 Jul 29, 2009

Copy link to clipboard

Copied

One approach might be to convert the list to an array and use arrayMax/arrayMin.  Assuming the list contains valid numbers, of course.

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 ,
Jul 29, 2009 Jul 29, 2009

Copy link to clipboard

Copied

Hi

Thanks for the reply.

Ok, so my next question would be... how do i convert that list to an array?

Excuse my ignorance. Im quite new to it!

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
Valorous Hero ,
Jul 29, 2009 Jul 29, 2009

Copy link to clipboard

Copied

Use the very well named ListToArray() function .. and definitely bookmark the online documentation 😉  The functions by category view is invaluable.

http://livedocs.adobe.com/coldfusion/8/functions-pt0_13.html

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
Community Expert ,
Jul 29, 2009 Jul 29, 2009

Copy link to clipboard

Copied

<cfset sortedList = listSort(thelist, "numeric", "Asc")>

min: <cfoutput>#listFirst(sortedList)#</cfoutput><br>
max: <cfoutput>#listLast(sortedList)#</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
Engaged ,
Jul 30, 2009 Jul 30, 2009

Copy link to clipboard

Copied

If you take this approach (which is a fine one), don't forget to build error-tolerance into the process, by means of the <cftry> and <cfcatch> tags.

It is reasonable to assume that, from time to time, this routine may be handed un-processable inputs, which will result in various kinds of exceptions being "thrown."  Your application, however, should not "fall flat on its face" when this occurs.  Instead, it should "catch" them and respond to the situation in some intelligent way.

This is, by the way, a perfectly-appropriate validation technique for cases like this.  You know that "ka-ka might occur," whether it is highly-likely or not-at-all.  Instead of spending gobs of computing-cycles checking every single input against "what might go wrong," you simply post someone in the outfield with a big glove.  He might spend weeks with nothing to do, but each and every time "ka-ka occurs," he will catch the ball.

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
Community Expert ,
Jul 30, 2009 Jul 30, 2009

Copy link to clipboard

Copied

LATEST
ka-ka occurs

Quite philosophical for French readers.

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