Changes between Version 1 and Version 2 of Strings
- Timestamp:
- 11/22/10 20:22:43 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Strings
v1 v2 5 5 In Cobra code these are typed as '''String''' (on .Net this equates to System.String) 6 6 {{{ 7 #!cobra 7 8 var name as String 8 9 def capitalize(title as String) … … 11 12 Within cobra you can catenate Strings explicitly with '+' 12 13 {{{ 14 #!cobra 13 15 s1 = 'my' + 'string' # after which s1 == "mystring" 14 16 }}} … … 16 18 Cobra also supports Python-style string slicing: 17 19 {{{ 20 #!cobra 18 21 s = s[1:] # chop off first char 19 22 s = s[:-1] # chop off last char … … 39 42 Char literals are (usually) a single quoted character prefixed with a '''c'''. 40 43 {{{ 44 #!cobra 41 45 ch = c'x' 42 46 }}} … … 46 50 \n, \r, \t, \0 47 51 {{{ 52 #!cobra 48 53 nlch = c'\n' 49 54 tabch = c'\t' … … 60 65 expression at that point. 61 66 {{{ 67 #!cobra 62 68 x='hops' 63 69 print 'hi [x]' # outputs: hi hops … … 98 104 Usual form 99 105 {{{ 106 #!cobra 100 107 """ 101 108 Heres the doc string … … 104 111 e.g. 105 112 {{{ 113 #!cobra 106 114 class BigOne 107 115 """ … … 125 133 e.g. 126 134 {{{ 135 #!cobra 127 136 t = sharp'System.Type.GetType(qualifiedName)' 128 137 }}} 129 138 == Examples == 130 139 {{{ 140 #!cobra 131 141 s = 'A simple String' 132 142