Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCL: Need to delete "(double quotes) from line in tcl skipping first and last. exmaples are giv

Status
Not open for further replies.

shreeshail

Programmer
Feb 7, 2015
1
Following is the line i will get and i need to replace all double quotes from it and keep first and last double quote as it is.. how to do it?

"0 "ifx" "blrcom" "media" "00-00-00-01-01-00" "server" "10.10.10.1" "10.10.10.10" "255.255.255.0" "11.11.11.1" "192.168.1.1" 0 "14.14.14.1"";
 
Hi

Remove them all then put back the first and the last ? Of course, that works only if there is nothing before the first and after the last quote ( or there is, but a fixed text ).

Otherwise use one of these ( both supposing the original string is in variable $str ) :
Code:
[b]set[/b] part [teal][[/teal][b]split[/b] [navy]$str[/navy] [i][green]"[/green][/i][lime]\"[/lime][i][green]"[/green][/i][teal]][/teal]
[b]set[/b] newstr [teal][[/teal][b]join[/b] [teal][[/teal][b]list[/b] [teal][[/teal][b]lindex[/b] [navy]$part[/navy] [purple]0[/purple][teal]][/teal] [teal][[/teal][b]join[/b] [teal][[/teal][b]lrange[/b] [navy]$part[/navy] [purple]1[/purple] end[teal]-[/teal][purple]1[/purple][teal]][/teal] [i][green]""[/green][/i][teal]][/teal] [teal][[/teal][b]lindex[/b] [navy]$part[/navy] end[teal]]][/teal] [i][green]"[/green][/i][lime]\"[/lime][i][green]"[/green][/i][teal]][/teal]
Code:
[b]set[/b] first [teal][[/teal][b]expr[/b] [teal][[/teal][b]string[/b] first [i][green]"[/green][/i][lime]\"[/lime][i][green]"[/green][/i] [navy]$str[/navy][teal]][/teal] [teal]+[/teal] [purple]1[/purple][teal]][/teal]
[b]set[/b] last [teal][[/teal][b]expr[/b] [teal][[/teal][b]string[/b] last [i][green]"[/green][/i][lime]\"[/lime][i][green]"[/green][/i] [navy]$str[/navy][teal]][/teal] [teal]-[/teal] [purple]1[/purple][teal]][/teal]
[b]set[/b] newstr [teal][[/teal][b]string[/b] replace [navy]$str[/navy] [navy]$first[/navy] [navy]$last[/navy] [teal][[/teal][b]string[/b] map [teal]{[/teal][i][green]"[/green][/i][lime]\"[/lime][i][green]"[/green][/i] [i][green]""[/green][/i][teal]}[/teal] [teal][[/teal][b]string[/b] range [navy]$str[/navy] [navy]$first[/navy] [navy]$last[/navy][teal]]]][/teal]


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top