2017년 7월 28일 금요일

Tips&Tricks – Capitalizing 1st Letter of Every Word


It was asked how you could capitalize 1st letter of every word in a sentence.
Below is a procedure that can take any sentence and will capitalize first letter of every word. For this, I have created a procedure-with-return called “capitalize”. The procedure accepts an argument “text”, performs some functions and then returns a result. This means we can invoke the procedure and pass it some Text data, and then expect it to return a result. When invoked, the “capitalize” procedure
1. Initializes a global variable “varTemp”
2. It then uses the “split at spaces” block to split the Text into pieces separated by spaces (i.e. splits into words). Once split, it will assign the List to “item” variable
3. Next, we use a for-each block to loop through the newly created list of words. For each word,
   1. Using “segment” we extract 1st letter of the word and convert it to upper case
   2. Using “segment” we extract rest of the word starting 2nd position
   3. We join (i.e. concatenate) varTemp (see 1)  + 3.i + 3.ii and add a blank space to the end
4.  Once the loop is completed, we use “trim” to get rid of last blank space and then return the result to the caller

image
  
Variation

Update above procedure to use local-variable instead of global. For purpose of tutorial, to keep blocks presentation simpler, global variable was used. Try to use a local-variable for the procedure.


댓글 없음:

댓글 쓰기