Solved

Basic regular expression

Posted on 2009-07-06
6
147 Views
Last Modified: 2013-11-07
Hi

I need help removing some characters from an input string. When the input string is stored in sql server 2005 the characters appear as squares. What characters are these? I thought perhaps they were line breaks as there are 2 of these characters at the end of each line of text (by that i mean the 2 characters together encode a line break). Whatever they are i would like to remove them from my input and I don't know what regular expression i need to match them

many thanks
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
crisco96 earned 500 total points
ID: 24786054
You can just do a replace

StringVariable.Replace("\n", "").Replace("\r", "")
0
 

Author Comment

by:andieje
ID: 24786455
thanks for yoru reply
why are you doing that in 2 separate replace calls?
0
 
LVL 15

Expert Comment

by:crisco96
ID: 24786872
I think I've heard somewhere that the way linux and windows handles carriage returns is different, like I think windows used \n\r, where linux just does \n, so just to be safe I replaced both separately with an empty string.
0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24787365
You might want to copy the text into a text editor to verify that the boxes do indeed represent line breaks (most likely they are, but if they're not, you might as well know in advance).

Also,

    *nix: LF (\n)
    Windows: CR (\r) + LF (\n)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24787371
For the last post, the order is as posted for Win.:  \r\n
0
 

Author Closing Comment

by:andieje
ID: 31600197
many thanks
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question