Re: remove new line in constant

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



ttan <ttan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> How do I remove new line in constant if I have a string like this
>
> string st1 ="\abc\def";

That's not a valid string - \d isn't a valid escape sequence. It also
doesn't contain any newlines...

> I use string trim but it doesn't work.
>
> string st2;
> for (int i = 0; i<st1.Lenght; i++)
> {
> st2 = st1.trim("\n".ToCharArray());
> }
>
> any idea?

That won't compile either, for various reasons. It's also entirely
unclear what purpose you expect the loop to serve. In future, it would
be well worth you producing a short but complete example which can be
compiled so that people can see your problem more clearly. See
http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

In this case, I believe your problem is that Trim only looks at the
start and end of the string. You should use Replace to replace all
occurrences.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: How can I ensure that I always have a list?
    ... set contentsList [string trim $contentsList] ... then never perform string transformations on the ... set cannotOpenFile [catch { ... It appears you are dealing with XML -- STOP, ...
    (comp.lang.tcl)
  • Re: How can I ensure that I always have a list?
    ... set contentsList [string trim $contentsList] ... then never perform string transformations on the ... with string commands it will always remain a list and can contain any ... set cannotOpenFile [catch { ...
    (comp.lang.tcl)
  • Re: How can I ensure that I always have a list?
    ... set contentsList [string trim $contentsList] ... then never perform string transformations on the ... set cannotOpenFile [catch { ... Do not attempt to parse the XML yourself, you will make mistakes (as evidenced by your post. ...
    (comp.lang.tcl)
  • Re: beginner question
    ... Returns a value equal to string except that any leading or trailing ... characters from the set given by chars are removed. ... % string trim $str abc ... abc def 123 ...
    (comp.lang.tcl)
  • Re: PRODUCT calculation in queries
    ... The Microsoft Jet database engine could not find the input table or query ... After pasting it into the code window, choose Compile on the Debug menu. ... Function Product(strField As String, strTable As String, _ ... Dim dblResult As Double ...
    (microsoft.public.access.queries)