0

I have a string as follows :

set str = "HELLO SO COMMUNITY| CAN YOU HELP ME"
foreach word ($str)
    echo $word
end

Presently, this prints HELLO and then SO and then COMMUNITY and so on. I want the delimeter for the printing to be | . SO the output should be HELLO SO COMMUNITY and then CAN YOU HELP ME. Does anyone know how to do this.

supergra
  • 1,578
  • 13
  • 19
Programmer
  • 6,565
  • 25
  • 78
  • 125

1 Answers1

0
set str = "HELLO SO COMMUNITY| CAN YOU HELP ME"

set delimiter = '|'
set special_char = '_' # A character you know doesn't appear in your strings

set words = `echo $str | sed "s/ /$special_char/g" | sed "s/$delimiter/ /g"`
# words now contains "HELLO_SO_COMMUNITY _CAN_YOU_HELP_ME"

foreach word ($words)
    echo $word | sed "s/$special_char/ /g"
end

Replace special_char with a character that you know does not appear in your strings. Just be careful with any special characters. I'd avoid *, ?, $, \, and other tokens that might be interpreted by cshell. Rule #1 of cshell is that it always interprets them in the wrong way... :P

supergra
  • 1,578
  • 13
  • 19