Case Conversion Example
Model was written in NetLogo 5.0.4
•
Viewed 667 times
•
Downloaded 160 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
NetLogo doesn't have primitives for converting upper to lower case, or vice versa. This example includes procedures that accomplish these tasks.
Comments and Questions
Click to Run Model
to try-it let input user-input "Type any string." user-message word "In all caps, that's: " upper-case-string input user-message word "And in all lower case, it's: " lower-case-string input end ;;; ;;; Here are the procedures, suitable for copying and pasting into ;;; your own models. ;;; ;;; ;;; upper-case-string and lower-case-string are recursive procedures ;;; that operate on the input string one character at a time. ;;; upper-case-char and lower-case-char are used for converting ;;; the individual characters. ;;; to-report upper-case-string [s] ifelse empty? s [ report "" ] [ report word (upper-case-char first s) (upper-case-string butfirst s) ] end to-report upper-case-char [c] let pos position c "abcdefghijklmnopqrstuvwxyz" ifelse pos = false [ report c ] [ report item pos "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ] end to-report lower-case-string [s] ifelse empty? s [ report "" ] [ report word (lower-case-char first s) (lower-case-string butfirst s) ] end to-report lower-case-char [c] let pos position c "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ifelse pos = false [ report c ] [ report item pos "abcdefghijklmnopqrstuvwxyz" ] end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 10 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Case Conversion Example.png | preview | Preview for 'Case Conversion Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.