ToUpper() ?
|
03-09-2015, 01:02 PM
Post: #1
|
|||
|
|||
ToUpper() ?
Hello,
I was wondering if we already have a ToUpper() function in the prime. I didn't find it in the catalogue, but chances are high I overlooked it. ToUpper("aaa") -> "AAA" |
|||
03-09-2015, 06:41 PM
Post: #2
|
|||
|
|||
RE: ToUpper() ?
I don't know a ready made function, but by combination of ASC and CHAR the result is the same.
Code: CHAR(ASC("abcdefg")-32) |
|||
03-09-2015, 07:50 PM
(This post was last modified: 03-09-2015 07:51 PM by PANAMATIK.)
Post: #3
|
|||
|
|||
RE: ToUpper() ?
(03-09-2015 06:41 PM)Thomas_Sch Wrote: I don't know a ready made function, but by combination of ASC and CHAR the result is the same. This obviously doesn't work with mixed upper and lower case strings like "Abcdefg". That's one small step for a man - one giant leap for mankind. |
|||
03-09-2015, 08:25 PM
(This post was last modified: 03-09-2015 08:26 PM by Mark Hardman.)
Post: #4
|
|||
|
|||
RE: ToUpper() ?
(03-09-2015 07:50 PM)PANAMATIK Wrote:(03-09-2015 06:41 PM)Thomas_Sch Wrote: I don't know a ready made function, but by combination of ASC and CHAR the result is the same. Nor would it work with accented Latin characters and other non-ASCII characters (e.g. œ to Œ). The case mapping and other special cases (e.g. for the German eszett [ß]) are fully defined and supported by the Unicode Standard under Case Mappings. It would certainly not be a trivial task to implement. Ceci n'est pas une signature. |
|||
03-09-2015, 08:45 PM
Post: #5
|
|||
|
|||
RE: ToUpper() ?
How about this:
- Define an array variable like Table(i) with the required dimension, for instance, 256 entries (or any other value, depending on the character table size to use). - Initialize each array position with the required Uppercase value. - As input, use the lowercase character binary weight as an index to the Table(i) array list and get the corresponding uppercase value. I didn't try to implement this kind of algorithm in the Prime myself, though. Jose Mesquita RadioMuseum.org member |
|||
03-10-2015, 06:27 AM
(This post was last modified: 03-10-2015 06:28 AM by Angus.)
Post: #6
|
|||
|
|||
RE: ToUpper() ?
I went with the following because mainly I am interessted in the alphanumeric keyboard. Initially I had problems while playing with integers and I wanted to have string constants converted to upper case. Poorly described problem. My fault.
Code:
|
|||
03-10-2015, 06:28 AM
Post: #7
|
|||
|
|||
RE: ToUpper() ?
Hello,
They are ~65536 chars in Prime, your solution would use 128KB of table... Clearly the fastest solution, but not the most memory friendly one... Cyrille |
|||
03-10-2015, 07:51 AM
Post: #8
|
|||
|
|||
RE: ToUpper() ?
(03-09-2015 06:41 PM)Thomas_Sch Wrote: (03-10-2015 06:27 AM)Angus Wrote: Combining the two above: Code: //convert 'a'..'z' to 'A'..'Z'. Leave others unchanged |
|||
03-10-2015, 08:10 AM
(This post was last modified: 03-10-2015 08:25 AM by Angus.)
Post: #9
|
|||
|
|||
RE: ToUpper() ?
hello Didier,
do you have any experience if avoiding loops is a good idea? I mean performancewise? Like in matlab, I mean. |
|||
03-10-2015, 08:10 AM
Post: #10
|
|||
|
|||
RE: ToUpper() ?
(03-10-2015 07:51 AM)Didier Lachieze Wrote: Combining the two above:Great!! many thanks, i was thinking about a simple solution, but I trip over my feet ;-) please, please write a little tutorial about that, specifically about EXECON examples! |
|||
03-10-2015, 08:26 AM
Post: #11
|
|||
|
|||
RE: ToUpper() ?
yes, I forgot. THANK YOU! Great inspiration, indeed.
|
|||
03-10-2015, 08:34 AM
Post: #12
|
|||
|
|||
RE: ToUpper() ?
(03-10-2015 08:10 AM)Angus Wrote: hello Didier,I would say that it depends on what you do in the loop. Here, as it is a simple operation, the loop is faster than the combination of string to list (ASC), list processing (EXECON) and list to string (CHAR). |
|||
03-10-2015, 09:16 AM
Post: #13
|
|||
|
|||
RE: ToUpper() ?
Just a word about EXECON:
I would adress its elements as &11 instead &1 even if there is only a single list. When dealing with a second the &21 notation is used. In my eyes that is not straight. A straight and clear notation is worth a lot in my eyes. I tried &11 with a single list and it works. Do I understand correctly that you can only use relative offsets up to 9? I mean &11 is interpreted as first element, first list and not (implied first list) 11th relative element. |
|||
03-10-2015, 12:12 PM
(This post was last modified: 03-10-2015 12:17 PM by Didier Lachieze.)
Post: #14
|
|||
|
|||
RE: ToUpper() ?
(03-10-2015 09:16 AM)Angus Wrote: Just a word about EXECON:The notation is quite flexible but you can choose to explicitly specify the list number and the relative element position in the list. For example, with one list a single number after '&' specifies the relative position in the list: EXECON("&1+&2",{1,3,5}) is the same as EXECON("&11+&12",{1,3,5}) With two lists a single number after '&' specifies the list used (the relative position is 1 by default): EXECON("&1+&2",{1,3,5},{2,4,6}) is the same as EXECON("&11+&21",{1,3,5},{2,4,6}) (03-10-2015 09:16 AM)Angus Wrote: Do I understand correctly that you can only use relative offsets up to 9? I mean &11 is interpreted as first element, first list and not (implied first list) 11th relative element.Yes, this is clearly stated in the manual and the calculator help. Btw there is an error in the latest manual (but not in the calculator help): in the first example a '1' is missing after '&'. |
|||
03-10-2015, 12:55 PM
Post: #15
|
|||
|
|||
RE: ToUpper() ?
(03-10-2015 12:12 PM)Didier Lachieze Wrote: Btw there is an error in the latest manual (but not in the calculator help): in the first example a '1' is missing after '&'. Thanks. Looks like they missed that during the file conversion work last time. TW Although I work for HP, the views and opinions I post here are my own. |
|||
03-11-2015, 11:44 PM
Post: #16
|
|||
|
|||
RE: ToUpper() ?
Old-timer, assembler programmers would do something like this:
Code: CHAR(BITOR(ASC("ABcde"),#20h)) -> "abcde" |
|||
03-12-2015, 06:25 AM
(This post was last modified: 03-12-2015 06:30 AM by bobkrohn.)
Post: #17
|
|||
|
|||
RE: ToUpper() ?
Here's my versions of UCase and LCase.
Easy to understand. Actually this concept can be adapted to many other uses. Like a Filter. The BITAND & BITOR versions above didn't work correctly. This version works with spaces, numbers, etc. Code:
|
|||
03-12-2015, 03:49 PM
Post: #18
|
|||
|
|||
RE: ToUpper() ?
Hello,
I think that this should work... for A:= 1 to size(string) do if instring("abce....yz", string(A)) string(A):= string(A)+32; end; end; Cyrille |
|||
03-12-2015, 04:19 PM
(This post was last modified: 03-12-2015 04:58 PM by Claudio L..)
Post: #19
|
|||
|
|||
RE: ToUpper() ?
(03-10-2015 06:28 AM)cyrille de brébisson Wrote: Hello, Here's my solution in C (somebody can translate to Prime? Han perhaps?). These tables were prepared by me based on the Unicode standard, with help from a public document about case folding. I did it a few years back, so they might have added more symbols/ranges afterwards. Code:
Each table entry has the start and end codes of a range, and an offset value. If your character is within that range (both ends included), you need to add the offset to obtain the equivalent lowercase character (this table is for case-folding = tolower()). To be used for toupper(), you should simply add the offset to the start and end values to get the lowercase range, check if your character is within, and subtract the offset instead of adding it. EDIT: Forgot to mention, when the offset is 1, the uppercase and lowercase symbols are alternated. See the example code below. There's actually 2 tables. One for 16-bit unicode values and the second one for 32-bit unicode characters (there's only one range defined in 32-bits that can be folded). Code:
I'll leave it for the Prime gurus to make a proper Unicode compliant ToUpper() and ToLower(). In C the tables are only 1400 bytes, not sure how much space you need on the Prime. It's not the fastest, but it's the most embeddable method I could find. Feel free to use it. Claudio |
|||
03-12-2015, 04:44 PM
(This post was last modified: 03-12-2015 05:06 PM by bobkrohn.)
Post: #20
|
|||
|
|||
RE: ToUpper() ?
Cyrille, my Prime doesn't accept
string(A):= string(A)+32; Did not know that SIZE could be used on a String. Says nothing in Help. I have not experimented with the idea of using the "string(A)+n". I have to play with it! How many other Functions have unknown uses? |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)