Case Conversion Example

Case Conversion Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 435 times • Downloaded 111 times • Run 0 times
Download the 'Case Conversion Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


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.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Case Conversion Example Download this version
Uri Wilensky over 14 years ago Case Conversion Example Download this version

Attached files

File Type Description Last updated
Case Conversion Example.png preview Preview for 'Case Conversion Example' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.