473,699 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - Replace newline character in a text file

2 New Member
My problem is that I'll receive a large excel file from a customer that has hard return in one of the cells (i.e. pressing alt + enter to make a new line in a cell) and when I export it to a text file, the value for that cell will have quotes around it and have an unknown/unreadable character (the little boxes) inline with the text. I would like to use C# to build an application to batch check for this kind of error but I can't figure out how to remove the newline character that is in the text file. Any help would be much appreciated.
Feb 29 '08 #1
3 12331
Plater
7,872 Recognized Expert Expert
I recomend reading the data in and examining what the byte values of those characters are, to make sure you have them correct.
Then in your program you can read in the string and do a .Replace(TheVal ueOfThoseBytes, ""); to remove them.
Feb 29 '08 #2
GoalieDude
2 New Member
Thanks - that works really well. Now my next question is that say I want to define my own delimiters to search between - in my case quotation marks - how would you go about doing that? Is it possible in C#?
Mar 3 '08 #3
Plater
7,872 Recognized Expert Expert
Well if your delimeters are already in the file, you can use the .Split() function to create an array of each of the sections between delimeters.
Mar 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
10289
by: Charles Erwin | last post by:
Is there any way, upon scanning in a file line by line to avoid missing the last line if there is not a newline character (aka you have to hit return on the last line of input in your file). I was sure that there was a way around it but it escapes me if there is one. Thanks Charles Erwin
18
21840
by: William Payne | last post by:
Hello, I need to write a program that opens a text file and scans the entire file for a specific line and when that line is found, a particular word on that line is to be replaced. The new word is given as an argument to the program. I wrote a small test program that doesn't work because strcmp() fails to find a matching line. Here's the code: #include <stdio.h> #include <string.h> int main(int argc, char** argv)
14
3269
by: Etu | last post by:
Hi, I have a string: string c = "'abc' \"cde\", 'mno' \"xyz\","; how can I use the c.Replace(???, ???) method to have this string: "'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
6
29626
by: Marty | last post by:
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, '_');
4
3125
by: Neo Geshel | last post by:
Greetings I am using VB in my ASP.NET project that uses an admin web site to populate a database that provides content for a front end web site. I am looking for a way to use replace() to replace multiple entries of an object within a string. That is, if a user hit twice to create one new line, but just once to create another, I want both types ( & twice to create a new line (by creating a blank line between paragraphs). ...
6
8864
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi Regex.Replace("<stuff>text</stuff>", "<stuff>", "<stuff>\n" would give yo <stuff text</stuff
29
3445
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
4
14525
by: jpierson | last post by:
Hi, I'm having a few problems with the replace function for replacing characters in a textbox. "C:\" is the string i am tryin to remove ,with it a command I am sending does not work. txtS_Filename.Text.Replace("C:\", ""); The compiler has a problem with the newline slash character but even
23
13500
by: dkirkdrei | last post by:
I am having a bit of trouble trying to double up on slashes in a file path. What I am trying to do is very similar to the code below: <? $var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf"; $new = preg_replace("\\", "\\\", "$var"); ?> Code above produces the following error:
0
9172
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...
0
9032
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
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
8880
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
6532
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
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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.