Re: set character at string position



Lisa Pearlson wrote:
Hi,

I looked at the string class, but I don't see how I can set/replace a character on a certain string position.
In C I'd do something like:


char s[] = "Hello";
s[2] = 'x';

This would give "Hexlo"

How do I this in Tcl?

Lisa



set s "Hello" set s [string replace $s 2 2 x]

.



Relevant Pages

  • set character at string position
    ... I looked at the string class, but I don't see how I can set/replace a ... character on a certain string position. ...
    (comp.lang.tcl)
  • Re: set character at string position
    ... > I looked at the string class, but I don't see how I can set/replace a ... > character on a certain string position. ... Have you considered buying a Tcl book? ...
    (comp.lang.tcl)
  • Re: set character at string position
    ... > I looked at the string class, but I don't see how I can set/replace a ... > character on a certain string position. ...
    (comp.lang.tcl)
  • Re: Restricting the alphabet of a string
    ... implement a bit string class. ... as an extension to from trinary strings). ... raise ValueError("illegal character at index " + str(i) ...
    (comp.lang.python)
  • Re: String matches() method
    ... >>Sharp wrote: ... >>>I would like to use the matchesmethod of the String class to test the ... x is suppose to be a character. ... >Your suggested regular expression works, but I dont fully understand it. ...
    (comp.lang.java.programmer)