HP Forums

Full Version: ToUpper() ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(03-12-2015 04:44 PM)bobkrohn Wrote: [ -> ]My Prime doesn't accept

string(A):= string(A)+32;

it seems that string should not be used as a variable name, try s instead.

Btw there are two other changes required: add CHAR and replace +32 by -32. I also prefer to use a local variable for the loop index.

Code:
EXPORT ToUpper(s)
BEGIN
LOCAL i;
  for i:= 1 to size(s) do
    if instring("abcdefghijklmnopqrstuvwxyz", CHAR(s(i))) then
      s(i):= s(i)-32;
    end;
  end;
  RETURN s;
END;
This ability to treat a String variable as a List was totally unknown to me.
What threw me was, yes, the use of a Home variable (A).
Awesome. I'm learning something new. A fresh tool in the toolbox.
Love this kind of thinking.

On this Forum I have seen several great "unintended uses" for functions that have been discovered.
Is there a file document somewhere with a list of these useful gems??

I played a little with the SIZE function (versus DIM)

According to Help:
DIM is for Strings
SIZE is for Lists


str:= "ABCDEF";
DIM(str) returns 6 as expected
SIZE(str) returns 6 as unexpected


on Lists
L1 := {31,32,33,34,35,36};

SIZE(L1) returns 6 as expected
DIM(L1) returns {1,1,1,1,1,1} unexpected
I guess it treats each number as an individual List?

Now to try and find a use for DIM(list)


Not everything that glitters is Gold
and not everything that is Gold glitters
If its about DIMensions, and SIZE matters, don't forget about:

length(), for lists, strings, or objects

-Dale-
Hello,


DIM and SIZE are synonyms (they point to the same function).

length is a CAS function, so will be much slower as it needs to convert the string to a CAS object and to get the result back from CAS to numerical.

variable indexing works for lists, matrices and strings.
Note that if you have a string in a list of list, you can do var(1,2,3) to get the 3rd character of the 2nd list in the first list of the list stored in var!

Codding this was a JOY!

Enjoy,

Cyrille
L1 := {31,32,33,34,35,36};

SIZE(L1) returns 6 as expected
DIM(L1) returns {1,1,1,1,1,1} unexpected

Educational Question.
If SIZE and DIM are equal why do I get different results? (from Home Screen)
The help description says that
DIM() number of characters in a string.
SIZE() number of elements in a list.
length() number of elements in a list, string or object.

SIZE and length both return 6 elements.
DIM correctly reports 1 character for each element in the list if èach element is the CHAR number, in your example.
with s being the string, here is another way to do a ToUpper..

L1:= ASC(s);
return CHAR(L1-((97<=L1) AND (122>L1))*32);
Pages: 1 2
Reference URL's