Dec 23, 2002 #1 guyleve Programmer Dec 23, 2002 1 IL Hi. is it possible to split a word into a list containing it's letters, for example can i split A12 into A 12 or A 1 2 please help.
Hi. is it possible to split a word into a list containing it's letters, for example can i split A12 into A 12 or A 1 2 please help.
Dec 23, 2002 #2 tdatgod Programmer Jul 21, 2001 601 US Hi, Does it have to be CSH? I mean it may be simpler in other shell languages like PERL. Anyway in CSH to make a array of @ x = 1 set a = "A12" set b = `expr length $a` set q = "" while ( $x <= $b ) set q = ( $q `expr substr $a $x 1` ) @ x ++ end echo " q[1] == $q[1] " echo " q[2] == $q[2] " echo " q[3] == $q[3] " set q = ( $q `expr substr $a $x 1` ) q[1] == A q[2] == 1 q[3] == 2 if you don't like..... set q = ( $q `expr substr $a $x 1` ) you could use set q = ( $q `echo $a | cut -c $x` ) now if you actually had a desire to put the first letter in one and the rest in another set a = "A12" set b = `echo $a | cut -c 1 ` set c = `echo $a | cut -c 2- ` echo "b == $b" echo "c == $c" b == A c == 12 or you could make an array set a = "A12" set b = `echo $a | cut -c 1 ` set c = `echo $a | cut -c 2- ` set q = ( $b $c ) echo " q[1] == $q[1] " echo " q[2] == $q[2] " q[1] == A q[2] == 12 Upvote 0 Downvote
Hi, Does it have to be CSH? I mean it may be simpler in other shell languages like PERL. Anyway in CSH to make a array of @ x = 1 set a = "A12" set b = `expr length $a` set q = "" while ( $x <= $b ) set q = ( $q `expr substr $a $x 1` ) @ x ++ end echo " q[1] == $q[1] " echo " q[2] == $q[2] " echo " q[3] == $q[3] " set q = ( $q `expr substr $a $x 1` ) q[1] == A q[2] == 1 q[3] == 2 if you don't like..... set q = ( $q `expr substr $a $x 1` ) you could use set q = ( $q `echo $a | cut -c $x` ) now if you actually had a desire to put the first letter in one and the rest in another set a = "A12" set b = `echo $a | cut -c 1 ` set c = `echo $a | cut -c 2- ` echo "b == $b" echo "c == $c" b == A c == 12 or you could make an array set a = "A12" set b = `echo $a | cut -c 1 ` set c = `echo $a | cut -c 2- ` set q = ( $b $c ) echo " q[1] == $q[1] " echo " q[2] == $q[2] " q[1] == A q[2] == 12