Ad esempio, desidero dividere "uno, due, tre" con una virgola come delimitatore e utilizzare un ciclo per elaborare separatamente la sottostringa risultante.Come dividere una stringa in CSH?
7
A
risposta
5
Ad esempio:
set s = "one,two,three"
set words = `echo $s:q | sed 's/,/ /g'`
foreach word ($words:q)
echo $word:q
end
Ma considerare se csh è lo strumento giusto per qualsiasi lavoro che stai facendo:
http://www.bmsc.washington.edu/people/merritt/text/cshbad.txt
7
Una soluzione più semplice rispetto a quello attuale presentato comporta l'uso del Modificatore di sostituzione incorporato: non vi è alcun motivo o motivo per utilizzare inutilmente un ciclo o una sostituzione di comando esterna in questo caso:
set list = one,two,three
set split = ($list:as/,/ /)
echo $split[2] # returns two
() crea una lista, il: s è il modificatore di sostituzione e: come ripete la sottotitolazione tutte le volte che è necessario.
Inoltre, t/csh non richiede la citazione di stringhe nude, né variabili che non richiedono una valutazione forzata.
1
set list = one,two,three
foreach i ($list:as/,/ /)
echo $i
end
Problemi correlati
- 1. Come dividere una stringa in una lista?
- 2. dividere una stringa in Python
- 3. Dividere una stringa in VB.NET
- 4. Come dividere una stringa in make?
- 5. Come dividere una stringa in Python?
- 6. come dividere una stringa in JavaScript
- 7. Come dividere una stringa delimitata in una matrice in awk?
- 8. Come dividere stringa da stringa in PowerShell
- 9. Come dividere una stringa all'ennesima occorrenza?
- 10. Come dividere una stringa con angularJS
- 11. come dividere una stringa con newline
- 12. Come dividere una stringa con php
- 13. Come posso dividere una stringa contenente emoji in una matrice?
- 14. Dividere una stringa in lettere maiuscole
- 15. Come dividere una stringa argomento in stile Bash in Ruby?
- 16. Come dividere una stringa in maiuscolo e minuscolo in JavaScript?
- 17. Come dividere una stringa in token in C?
- 18. Come dividere i caratteri Tamil in una stringa in PHP
- 19. Come dividere una stringa in un particolare carattere in Rebol
- 20. Come dividere in modo affidabile una stringa in Python?
- 21. Dividere una stringa e archiviarla in una matrice in lua
- 22. Come dividere la stringa in una matrice di più parole?
- 23. come dividere una stringa con più delimitatori in vba excel?
- 24. Come dividere una stringa di directory in Ruby?
- 25. Come dividere una stringa e ottenere l'ultima corrispondenza in jQuery?
- 26. Come dividere una stringa e assegnarla alle variabili in Golang?
- 27. Come dividere una stringa CamelCase nelle sottostringhe in Ruby?
- 28. vb.net: si può dividere una stringa da una stringa
- 29. Dividere la stringa in parole
- 30. Come dividere stringa sulla barra in bash
Grazie. Cosa significa: q significa qui? – zzhang
cita la variabile; '$ s: q' è simile a' "$ s" '. Non è necessario per questo esempio, ma potrebbe essere in altri casi (ad esempio, dove si hanno spazi bianchi nei dati). –