Post Reply 
ToUpper() ?
03-12-2015, 04:53 PM
Post: #21
RE: ToUpper() ?
(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;
Find all posts by this user
Quote this message in a reply
03-12-2015, 08:05 PM (This post was last modified: 03-12-2015 08:10 PM by bobkrohn.)
Post: #22
RE: ToUpper() ?
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
Find all posts by this user
Quote this message in a reply
03-12-2015, 08:44 PM
Post: #23
RE: ToUpper() ?
If its about DIMensions, and SIZE matters, don't forget about:

length(), for lists, strings, or objects

-Dale-
Find all posts by this user
Quote this message in a reply
03-13-2015, 06:18 AM
Post: #24
RE: ToUpper() ?
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
Find all posts by this user
Quote this message in a reply
03-13-2015, 11:28 PM
Post: #25
RE: ToUpper() ?
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)
Find all posts by this user
Quote this message in a reply
03-14-2015, 04:45 AM
Post: #26
RE: ToUpper() ?
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.
Find all posts by this user
Quote this message in a reply
03-17-2015, 07:11 AM
Post: #27
RE: ToUpper() ?
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);
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)