Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried :
strMyString.Replace('\r', '_');
strMyString.Replace('\n', '_');
or
strMyString.Replace(System.Environment.NewLine, '_');
and it doesn't work, what is missing?
Thank you!
Marty 6 29594
Hello
try...
strMyString = strMyString.Replace("\r\n","_");
"Marty" <xm******@hotmail.com> wrote in message
news:PzK7f.55138$Io.27031@clgrps13... Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or strMyString.Replace(System.Environment.NewLine, '_'); and it doesn't work, what is missing?
Thank you! Marty
Marty
This works for me....
string strText = "Text me " + Environment.NewLine + "Text me " +
Environment.NewLine;
strText = strText.Replace(Environment.NewLine, "_");
or this works..
string strText = "Text me " + Environment.NewLine + "Text me " +
Environment.NewLine;
strText = strText.Replace("\r\n", "_");
Vijay
"Marty" <xm******@hotmail.com> wrote in message
news:PzK7f.55138$Io.27031@clgrps13... Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or strMyString.Replace(System.Environment.NewLine, '_'); and it doesn't work, what is missing?
Thank you! Marty
Marty,
You almost had it. The Replace() method returns the modified string. Try
this...
string strMyString = "This is\r\n some line\r wrapping\n text";
strMyString = strMyString.Replace("\r\n", "_").Replace("\r",
"_").Replace("\n", "_");
John
"Marty" <xm******@hotmail.com> wrote in message
news:PzK7f.55138$Io.27031@clgrps13... Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or strMyString.Replace(System.Environment.NewLine, '_'); and it doesn't work, what is missing?
Thank you! Marty
I think you have to assign it to a different string, this is a little
bit differnet with the C++ string.
Marty wrote: Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or strMyString.Replace(System.Environment.NewLine, '_');
and it doesn't work, what is missing?
Thank you! Marty
Marty wrote: I would like to replace "\r\n" by "_" within a specific string.
I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or strMyString.Replace(System.Environment.NewLine, '_');
and it doesn't work, what is missing?
Strings are immutable - String.Replace doesn't change the contents of
the string you call it on; instead, it returns a new string.
To achieve your stated aim, you should use:
strMyString = strMyString.Replace("\r\n", "_");
Note that your first attempt would replace bare carriage returns and
bare line feeds with underscores, and would replace "\r\n" with "__"
instead of "_".
Your second attempt is closer, but will only replace "\r\n" on Windows
- on other platforms, it will replace whatever the platform default
newline string is with "_".
Jon
Thanks guys for your help :)
Marty
Marty wrote: Hi,
I would like to replace "\r\n" by "_" within a specific string.
I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or strMyString.Replace(System.Environment.NewLine, '_');
and it doesn't work, what is missing?
Thank you! Marty This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BJörn Lindqvist |
last post by:
I think it would be cool if you could refer to instance variables
without prefixing with "self." I know noone else thinks like me so
Python will never be changed, but maybe you can already do it...
|
by: Alexander Bartzas |
last post by:
I'm trying to compile route.cpp part of the NetBench Suite (UCLA) and...:
> g++ packet.cpp radix.cpp route.cpp -o route
There is no problem in the compilation of the code but when I try to run...
|
by: KENNY L. CHEN |
last post by:
Dear experts,
I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO)
and TEST1 (COL1,COL2,REC_NO).
Both tables are unique-indexed on (COL1,COL2,REC_NO).
I think the following...
|
by: Erik R.N. |
last post by:
Hi
I have a ACCESS2002 table with a date-field in format "dd-mm-yyyy"
which I "export" to a txt-file ( ; and " " )
and upload the txt-file to a MYSQL-table
where the datefield is a varchar-field....
|
by: napi |
last post by:
I think you would agree with me that a C compiler that directly
produces Java Byte Code to be run on any JVM is something that is
missing to software programmers so far. With such a tool one could...
|
by: SenthilSS |
last post by:
My application produces XML Data files which have XML namespace qualified XML
elements (nodes), but the namespace itself is not declared in the data file.
My task is to read these data files in a...
|
by: Bernd Hohmann |
last post by:
I have a question about using "*" in (sub)queries.
This example query counts the number of records for a certain customer
starting with record "80172" and stops after 10 rows.
SELECT...
|
by: SharpCoderMP |
last post by:
hi,
i'm writing a console application and i would like to be able to safely
retrive password from the user, so noone can see how it is being typed.
consider this scenario:
Console.Write("Enter...
|
by: matheussousuke |
last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails.
The goal is: Make it send the email with the URL...
|
by: sameera s |
last post by:
Hi,
I am doing a paging task. In order to do that I want to get data 10 by 10 raws from a table. How can I do this using "rownum" ?
I tried in this way
SELECT FROM (
SELECT...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |