473,695 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remove new line in constant


How do I remove new line in constant if I have a string like this

string st1 ="\abc\def";

I use string trim but it doesn't work.

string st2;
for (int i = 0; i<st1.Lenght; i++)
{
st2 = st1.trim("\n".T oCharArray());
}

any idea?
thanks

Nov 17 '05 #1
5 28167

"ttan" <tt**@discussio ns.microsoft.co m> wrote in message
news:13******** *************** ***********@mic rosoft.com...

How do I remove new line in constant if I have a string like this

string st1 ="\abc\def";

I use string trim but it doesn't work.

string st2;
for (int i = 0; i<st1.Lenght; i++)
{
st2 = st1.trim("\n".T oCharArray());
}


Trim only works on characters at the beginning and end of the string. You
want something like

st2 = st1.Replace("\n ","");
Nov 17 '05 #2
ttan <tt**@discussio ns.microsoft.co m> 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".T oCharArray());
}

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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
Sorry for the unclear.

Problem is, I read in an mac address as an string "0040840c02 90"
when I convert this into byte and it gave me 12 bytes by using :

byte [] buffer = Encoding.ASCII. GetBytes(this.S ource.text);

But I'm only allow to store the mac address into 6 bytes.
[FieldOffset(0)] byte [] mac_add; //6 bytes
[FieldOffset(6)] byte [] ether_type; // 2 bytes
........
"Jon Skeet [C# MVP]" wrote:
ttan <tt**@discussio ns.microsoft.co m> 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".T oCharArray());
}

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 - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4
string st1 ="abc\r\ndef ";
string st2 = st1.Replace("\r \n\", "");

HTH

"ttan" <tt**@discussio ns.microsoft.co m> wrote in message
news:13******** *************** ***********@mic rosoft.com...

How do I remove new line in constant if I have a string like this

string st1 ="\abc\def";

I use string trim but it doesn't work.

string st2;
for (int i = 0; i<st1.Lenght; i++)
{
st2 = st1.trim("\n".T oCharArray());
}

any idea?
thanks

Nov 17 '05 #5
ttan <tt**@discussio ns.microsoft.co m> wrote:
Sorry for the unclear.

Problem is, I read in an mac address as an string "0040840c02 90"
when I convert this into byte and it gave me 12 bytes by using :

byte [] buffer = Encoding.ASCII. GetBytes(this.S ource.text);

But I'm only allow to store the mac address into 6 bytes.
[FieldOffset(0)] byte [] mac_add; //6 bytes
[FieldOffset(6)] byte [] ether_type; // 2 bytes
.......


Well, it's not at all clear to me how that's related to your original
question, but it seems to me that you've got a hex string with 6 bytes
encoded there, which presumably needs to go in mac_add, and I'm not
sure about ether_type...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11774
by: Amy L. | last post by:
Is there a way through .net to read a very large text file (400MB+) backwards line by line. In system.io the filestream class has a "seek" method but the only read method requires you to know how many bytes to read in. My problem is that the line length of this log file is not constant so there is no easy way to read one line in. The only thing that is constant is that each line is terminated by a carriage return. If my only option...
4
13950
by: Simon Harris | last post by:
Hi All, I am trying to write a function that will remove all carriage returns from a string, so that the string of words can be used as meta keywords. So far I have: Function RemoveCR(strText) strText = Replace(strText,chr(13),"")
11
5288
by: lovecreatesbeauty | last post by:
Hello experts, Is const_cast only applied to pointers or references? If I have a constant object, then how can I remove constant attribute from it? #include <vector> #include <string> using namespace std;
2
9532
by: collinm | last post by:
hi here my code FILE *fp; char *line; #define LINE_MAX 30 fp = fopen("test1.txt", "r");
3
38035
by: Chakkaradeep | last post by:
Hi all, i have a string, str_old="E:\a\b\c.exe", and i want to change to str_new="E:\\a\\b\\c.exe".
2
1947
by: gavino | last post by:
http://hashphp.org/pastebin.php?format=plain&pid=8181 the $txt line here is giving me problems along with the two if lines below complaint from log: PHP Notice: Use of undefined constant depend - assumed 'depend' in /var/www/html/billingticket/sliputils.php3 on line 203 PHP Notice: Use of undefined constant problem - assumed 'problem' in /var/www/html/billingticket/sliputils.php3 on line 199
15
15622
by: DanielJohnson | last post by:
I am writing a program in which I am removing all the spaces from the string. I thought that I could do it two ways. One was parsing the string character by character and copying onto another output string. But this was trivial. The other option is to use pointers and shift all the characters after the space by one space to the left. I did this program using pointers and then using array too and I get segmentation fault. What is going...
21
5124
by: Timothy Madden | last post by:
Hello The examples in the php cli chapter in the manual end a line with "\n". For example echo "Total {$total}.\n"; Should it not be "\n" on Linux\Unix systems and "\r\n" on Windows systems ? And even "\r" on Macintosh ? How to I get the end of line marker of the current platform ?
11
3309
by: David | last post by:
Hi All, I am working on a script that is theoreticaly simple but I can not get it to work completely. I am dealing with a page spit out by .NET that leaves empty tags in the markup. I need a javascript solution to go behind and do a clean up after the page loads. The .NET will leave behind any combination of nested tags. Here is an example below. Even though the <spantags are not empty, as they contain <emtags they also need to be...
0
8572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8825
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6491
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.