Jump to content

Getting first number from string of numbers.


Koji Moonites
 Share

You are about to reply to a thread that has been inactive for 4600 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am working on a new project and am a little confused about the best way to handle a problem. I am trying to get the first number from a set of numbers of variable length. For example, I might have a set of numbers of 584739 and when entered into a function, it returns 5. Or I might have a set of numbers of 74832 and when entered into a function, it returns 7.

I can accomplish this mathematically but that would require about 50 lines, more than I really want to code if anyone has an easier way.

Thank you for your help :-)

Link to comment
Share on other sites

I don't have a clear understanding of your problem. 584739 and 74832 are not sets of numbers, they are integers. If you want a function to return a first digit of an integer that would be:

integer GetFirstDigit(integer src)
{
  if(src < 0) src=llAbs(src);
  return (integer)(llGetSubString((string)src,0,0));
}

if however you missed commas and actually have lists [5,8,4,7,3,9] and [7,4,8,3,2] (which would be indeed sets of numbers), you don't need a function. There is a system call: llList2Integer(list src, integer list_index)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4600 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...