Advertisement

03.19.2001 at 04:09AM PST, ID: 20093677
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

TCL: problem with REGSUB command

Tags: tcl, regsub
I need to use REGSUB command on a text containing the $ character. I tried to escape this character with some backslashes, but it seems that REGSUB command completely ignores them still trying to access a variable.
How can I solve this problem?
Start your free trial to view this solution
Question Stats
Zone: Software
Question Asked By: claud_io
Solution Provided By: hooker
Participating Experts: 2
Solution Grade: B
Views: 29
Translate:
Loading Advertisement...
03.20.2001 at 07:54AM PST, ID: 5942891

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.20.2001 at 08:10AM PST, ID: 5942918

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.21.2001 at 02:07AM PST, ID: 5945254

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.21.2001 at 05:48AM PST, ID: 5945802

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.22.2001 at 03:32AM PST, ID: 5949212

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.22.2001 at 03:45AM PST, ID: 5949242

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
12.07.2004 at 02:33PM PST, ID: 12769032

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.20.2001 at 07:54AM PST, ID: 5942891
The $ shouldn't cause any problems on it's own.

I would expect the problem to be the number of backslashes being used. Increase the number one by one until it works.

The exact number needed depends on whether you're escaping within pure tcl or within StoryServer commands.
And the number of non-pure TCL nested commands can affect - apparently the rule is that you must escape the character 2^n times where n is the degree of nests.

In my experience, trial and error gets you there in the end.

Cheers,
Dominic.
 
03.20.2001 at 08:10AM PST, ID: 5942918
The $ shouldn't cause any problems.

I would expect the problem to be the number of backslashes being used. Increase the number one by one until it works.

The exact number needed depends on whether you're escaping within pure tcl or within StoryServer commands.
And the number of non-pure TCL nested commands can affect - apparently the rule is that you must escape the character 2^n times where n is the degree of nests.

In my experience, trial and error gets you there in the end.

Cheers,
Dominic.
 
03.21.2001 at 02:07AM PST, ID: 5945254
I already tried this way starting with one backslash and increasing them little by little with no results ... at the moment I have to cicle into the string to substitute the $ character with a specific pattern, use regsub (I use it 99 times!!!!) and then cicle again to substitute the pattern with the original $.

The problem is that I build a complex tcl command into a string and then and evaluate it.
Here an example:

for {SET zy 1} {[SHOW zy] <= 99} {SET zy [expr [SHOW zy] + 1]} {
     set b "regsub -all \\"[SHOW char([SHOW zy])]\\" \\"$newtext\\" {\\\\[SHOW codHTML([SHOW zy])]} newtext"
     eval $b
}


 
03.21.2001 at 05:48AM PST, ID: 5945802
Can you give me a clear example that I can copy into my own environment to see
a) what you want to do but does not work
b) what you're doing instead.

Cheers.
 
03.22.2001 at 03:32AM PST, ID: 5949212
Claud_io,

I've given this more thought and I'm more aware of your problem than before.
The problem is that there are hidden meanings to certain characters with regsub and regexp.
The code below works for me up to character 48
[
set string {abcdef$ghi'}
for {set zy 1} {$zy <= 40} {incr zy} {
     regsub -all \\\\[format %c $zy] $string * string
}
NULL
]

similarly if it was just $ that you wanted to substitute, then this works:
regsub -all \\\\$ $string {\\&#0036;} string

However, there are two more complications. Firstly, for character 49, the "\\\\[format %c $zy]" of the first bit of code evaluates to \\1 which means the first matched string with regexp and regsub and not just match "1" (and the same problem exists for all numbers). This is a big problem! Also \\C seems to mean something too...

Secondly, if you want to loop through the characters and substitute the special characters with their entity representation, e.g. &#0036; then at 35 "#" would be changed to &#0035; but at 38 that would then be changed to &#0038;#0035; etc.

I hope I have explained all that in a way that can be understood by anyone else.

In other words, presumably your aim is to substitute all special characters with their html entity codes. I can't think of a nice and easy way to do it in one loop because you need \\ for some characters and not for others.

Cheers.
Accepted Solution
 
03.22.2001 at 03:45AM PST, ID: 5949242
[# This piece of code is used to convert an UTF-8 text read from DB to the correspondent HTML code ]

[
# a A with accent
SET codHTML(1) "&agrave;"
SET char(1) "[format "%c" 195][format "%c" 160]"
SET codHTML(2) "&aacute;"
SET char(2) "[format "%c" 195][format "%c" 161]"
SET codHTML(3) "&acirc;"
SET char(3) "[format "%c" 195][format "%c" 162]"
SET codHTML(4) "&atilde;"
SET char(4) "[format "%c" 195][format "%c" 163]"
SET codHTML(5) "&auml;"
SET char(5) "[format "%c" 195][format "%c" 164]"
SET codHTML(6) "&Agrave;"
SET char(6) "[format "%c" 195][format "%c" 128]"
SET codHTML(7) "&Aacute;"
SET char(7) "[format "%c" 195][format "%c" 129]"
SET codHTML(8) "&Acirc;"
SET char(8) "[format "%c" 195][format "%c" 130]"
SET codHTML(9) "&Atilde;"
SET char(9) "[format "%c" 195][format "%c" 131]"
SET codHTML(10) "&Auml;"
SET char(10) "[format "%c" 195][format "%c" 132]"

# e E with accent
SET codHTML(11) "&egrave;"
SET char(11) "[format "%c" 195][format "%c" 168]"
SET codHTML(12) "&eacute;"
SET char(12) "[format "%c" 195][format "%c" 169]"
SET codHTML(13) "&ecirc;"
SET char(13) "[format "%c" 195][format "%c" 170]"
SET codHTML(14) "&euml;"
SET char(14) "[format "%c" 195][format "%c" 171]"
SET codHTML(15) "&Egrave;"
SET char(15) "[format "%c" 195][format "%c" 136]"
SET codHTML(16) "&Eacute;"
SET char(16) "[format "%c" 195][format "%c" 137]"
SET codHTML(17) "&Ecirc;"
SET char(17) "[format "%c" 195][format "%c" 138]"
SET codHTML(18) "&Euml;"
SET char(18) "[format "%c" 195][format "%c" 139]"

# i I with accent
SET codHTML(19) "&igrave;"
SET char(19) "[format "%c" 195][format "%c" 172]"
SET codHTML(20) "&iacute;"
SET char(20) "[format "%c" 195][format "%c" 173]"
SET codHTML(21) "&icirc;"
SET char(21) "[format "%c" 195][format "%c" 174]"
SET codHTML(22) "&iuml;"
SET char(22) "[format "%c" 195][format "%c" 175]"
SET codHTML(23) "&Igrave;"
SET char(23) "[format "%c" 195][format "%c" 140]"
SET codHTML(24) "&Iacute;"
SET char(24) "[format "%c" 195][format "%c" 141]"
SET codHTML(25) "&Icirc;"
SET char(25) "[format "%c" 195][format "%c" 142]"
SET codHTML(26) "&Iuml;"
SET char(26) "[format "%c" 195][format "%c" 143]"

# o O with accent
SET codHTML(27) "&ograve;"
SET char(27) "[format "%c" 195][format "%c" 178]"
SET codHTML(28) "&oacute;"
SET char(28) "[format "%c" 195][format "%c" 179]"
SET codHTML(29) "&ocirc;"
SET char(29) "[format "%c" 195][format "%c" 180]"
SET codHTML(30) "&otilde;"
SET char(30) "[format "%c" 195][format "%c" 181]"
SET codHTML(31) "&ouml;"
SET char(31) "[format "%c" 195][format "%c" 182]"
SET codHTML(32) "&Ograve;"
SET char(32) "[format "%c" 195][format "%c" 146]"
SET codHTML(33) "&Oacute;"
SET char(33) "[format "%c" 195][format "%c" 147]"
SET codHTML(34) "&Ocirc;"
SET char(34) "[format "%c" 195][format "%c" 148]"
SET codHTML(35) "&Otilde;"
SET char(35) "[format "%c" 195][format "%c" 149]"
SET codHTML(36) "&Ouml;"
SET char(36) "[format "%c" 195][format "%c" 150]"

# u U with accent
SET codHTML(37) "&ugrave;"
SET char(37) "[format "%c" 195][format "%c" 185]"
SET codHTML(38) "&uacute;"
SET char(38) "[format "%c" 195][format "%c" 186]"
SET codHTML(39) "&ucirc;"
SET char(39) "[format "%c" 195][format "%c" 187]"
SET codHTML(40) "&uuml;"
SET char(40) "[format "%c" 195][format "%c" 188]"
SET codHTML(41) "&Ugrave;"
SET char(41) "[format "%c" 195][format "%c" 153]"
SET codHTML(42) "&Uacute;"
SET char(42) "[format "%c" 195][format "%c" 154]"
SET codHTML(43) "&Ucirc;"
SET char(43) "[format "%c" 195][format "%c" 155]"
SET codHTML(44) "&Uuml;"
SET char(44) "[format "%c" 195][format "%c" 156]"

# other simbols
SET codHTML(45) "&copy;"
SET char(45) "[format "%c" 194][format "%c" 169]"
SET codHTML(46) "&uml;"
SET char(46) "[format "%c" 194][format "%c" 168]"
SET codHTML(47) "&laquo;"
SET char(47) "[format "%c" 194][format "%c" 171]"
SET codHTML(48) "&raquo;"
SET char(48) "[format "%c" 194][format "%c" 187]"
SET codHTML(49) "&acute;"
SET char(49) "[format "%c" 194][format "%c" 180]"
SET codHTML(50) "&iexcl;"
SET char(50) "[format "%c" 194][format "%c" 161]"
SET codHTML(51) "&cent;"
SET char(51) "[format "%c" 194][format "%c" 162]"
SET codHTML(52) "&pound;"
SET char(52) "[format "%c" 194][format "%c" 163]"
SET codHTML(53) "&curren;"
SET char(53) "[format "%c" 194][format "%c" 164]"
SET codHTML(54) "&yen;"
SET char(54) "[format "%c" 194][format "%c" 165]"
SET codHTML(55) "&brvbar;"
SET char(55) "[format "%c" 194][format "%c" 166]"
SET codHTML(56) "&sect;"
SET char(56) "[format "%c" 194][format "%c" 167]"
SET codHTML(57) "&ordf;"
SET char(57) "[format "%c" 194][format "%c" 170]"
SET codHTML(58) "&not;"
SET char(58) "[format "%c" 194][format "%c" 172]"
SET codHTML(59) "&reg;"
SET char(59) "[format "%c" 194][format "%c" 174]"
SET codHTML(60) "&macr;"
SET char(60) "[format "%c" 194][format "%c" 175]"
SET codHTML(61) "&deg;"
SET char(61) "[format "%c" 194][format "%c" 176]"
SET codHTML(62) "&plusmn;"
SET char(62) "[format "%c" 194][format "%c" 177]"
SET codHTML(63) "&sup2;"
SET char(63) "[format "%c" 194][format "%c" 178]"
SET codHTML(64) "&sup3;"
SET char(64) "[format "%c" 194][format "%c" 179]"
SET codHTML(65) "&micro;"
SET char(65) "[format "%c" 194][format "%c" 181]"
SET codHTML(66) "&para;"
SET char(66) "[format "%c" 194][format "%c" 182]"
SET codHTML(67) "&middot;"
SET char(67) "[format "%c" 194][format "%c" 183]"
SET codHTML(68) "&cedil;"
SET char(68) "[format "%c" 194][format "%c" 184]"
SET codHTML(69) "&sup1;"
SET char(69) "[format "%c" 194][format "%c" 185]"
SET codHTML(70) "&ordm;"
SET char(70) "[format "%c" 194][format "%c" 186]"
SET codHTML(71) "&frac14;"
SET char(71) "[format "%c" 194][format "%c" 188]"
SET codHTML(72) "&frac12;"
SET char(72) "[format "%c" 194][format "%c" 189]"
SET codHTML(73) "&frac34;"
SET char(73) "[format "%c" 194][format "%c" 190]"
SET codHTML(74) "&iquest;"
SET char(74) "[format "%c" 194][format "%c" 191]"
SET codHTML(75) "&Aring;"
SET char(75) "[format "%c" 195][format "%c" 133]"
SET codHTML(76) "&AElig;"
SET char(76) "[format "%c" 195][format "%c" 134]"
SET codHTML(77) "&Ccedil;"
SET char(77) "[format "%c" 195][format "%c" 135]"
SET codHTML(78) "&ETH;"
SET char(78) "[format "%c" 195][format "%c" 144]"
SET codHTML(79) "&Ntilde;"
SET char(79) "[format "%c" 195][format "%c" 145]"
SET codHTML(80) "&times;"
SET char(80) "[format "%c" 195][format "%c" 151]"
SET codHTML(81) "&Oslash;"
SET char(81) "[format "%c" 195][format "%c" 152]"
SET codHTML(82) "&Yacute;"
SET char(82) "[format "%c" 195][format "%c" 157]"
SET codHTML(83) "&szlig;"
SET char(83) "[format "%c" 195][format "%c" 159]"
SET codHTML(84) "&aring;"
SET char(84) "[format "%c" 195][format "%c" 165]"
SET codHTML(85) "&aelig;"
SET char(85) "[format "%c" 195][format "%c" 166]"
SET codHTML(86) "&ccedil;"
SET char(86) "[format "%c" 195][format "%c" 167]"
SET codHTML(87) "&eth;"
SET char(87) "[format "%c" 195][format "%c" 176]"
SET codHTML(88) "&ntilde;"
SET char(88) "[format "%c" 195][format "%c" 177]"
SET codHTML(89) "&divide;"
SET char(89) "[format "%c" 195][format "%c" 183]"
SET codHTML(90) "&oslash;"
SET char(90) "[format "%c" 195][format "%c" 184]"
SET codHTML(91) "&yacute;"
SET char(91) "[format "%c" 195][format "%c" 189]"
SET codHTML(92) "&thorn;"
SET char(92) "[format "%c" 195][format "%c" 190]"
SET codHTML(93) "&yuml;"
SET char(93) "[format "%c" 195][format "%c" 191]"
SET codHTML(94) "&ldquo;"
SET char(94) "[format "%c" 226][format "%c" 128][format "%c" 156]"
SET codHTML(95) "&rdquo;"
SET char(95) "[format "%c" 226][format "%c" 128][format "%c" 157]"
SET codHTML(96) "&lsquo;"
SET char(96) "[format "%c" 226][format "%c" 128][format "%c" 152]"
SET codHTML(97) "&rsquo;"
SET char(97) "[format "%c" 226][format "%c" 128][format "%c" 153]"
SET codHTML(98) "&lt;"
SET char(98) "[format "%c" 60]"
SET codHTML(99) "&gt;"
SET char(99) "[format "%c" 62]"
]


[proc char2Html {dbString} {
# Table length
set len 99

# Quotes substitution with html tag &quot;
regsub -all {"} $dbString {\\&quot;} dbString

# $ symbol with string "_vgn_dollar".
set txlen [string length $dbString]
set newtext ""
for {set i 0} {$i < $txlen} {incr i} {
      set newcar "[string index $dbString $i]"

      # Escape of the symbol $
      if {$newcar == "$"} {set newcar "_vgn_dollar"}
      append newtext "$newcar"
}

# Substitution of all occurrences
# Si sostituiscono tutte le occorrenze definite in tabella trovate nella stringa di input.
for {SET zy 1} {[SHOW zy] <= $len} {SET zy [expr [SHOW zy] + 1]} {
      set b "regsub -all \\"[SHOW char([SHOW zy])]\\" \\"$newtext\\" {\\\\[SHOW codHTML([SHOW zy])]} newtext"
      eval $b
}

#  "_vgn_dollar" with string $ symbol.
regsub -all "_vgn_dollar" "$newtext" {$} newtext

return $newtext
}]

 
12.07.2004 at 02:33PM PST, ID: 12769032
I noticed your VERY long conversion from ASCII to character entities. While we're not using UTF-8 you might find this handy... It finds all the characters which are not ASCII (eg not decimal 33 - 126) and replaces them with a the character entity.

This code will regsub the non ascii characters
[
SET retStr "012345@ACDEabcdef„‘’“”•–ÀÅÆÐÒ"
regsub -all -nocase -- {([^[:ascii:]])} $retStr {\&#[scan \1 %c entity;set entity];} retStr;
set retStr [EVAL $retStr]
SHOW retStr
]

The output ==>
012345@ACDEabcdef&#8222;&#8216;&#8217;&#8220;&#8221;&#8226;&#8211;&#192;&#197;&#198;&#208;&#210;
 
 
20080236-EE-VQP-29