Re: Use strings in Mathematica, like in C?

*To*: mathgroup at smc.vnet.net*Subject*: [mg61370] Re: Use strings in Mathematica, like in C?*From*: albert <awnl at arcor.de>*Date*: Mon, 17 Oct 2005 02:29:35 -0400 (EDT)*References*: <disllm$mj5$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi, > int main() { > > char message[16] = "Hello!"; > message[n]='a'; > > /* ... other code ... */ > return(0); > > } > > This mean: Change the (n+1)th character (in C, array starts at 0) to the > specified character. > > Q: How can I obtain similar effect in Mathematica? This would be one possibility of many: StringReplacePart["hallo","e",{2,2}] anyway, this is not replacing the string "in place" so is not an exact equivalent of your C-Code. If you do complicated operatons on strings you might want to either check all the String*-Functions that you can find by evaluating: ?String* and also look at the RegularExpressions that are new in version 5.1. If your strings are large and/or in place operations are important, you might need to convert your strings to a list of characters. This is not the same in Mathematica (unlike in C) and it is not perfectly efficient as such. But to my knowledge it is the only possibility to do in place replacements. Check the following: In[14]:= a=Characters["hello"] Out[14]= {h, e, l, l, o} In[15]:= a[[2]]="e" Out[15]= e In[16]:= a Out[16]= {h, e, l, l, o} I hope that's correct and helps.. albert