We help IT Professionals succeed at work.

c# sql server retuning an extr \ when a " is found

237 Views
Last Modified: 2013-12-16
have a data base sql server that i am running the records from , and one of the fields that is returned will hold the data of  .... <iabc-type="ppub">  .....  but when its returned it comes back as "<iabc-type=\"ppub\">"  with the extra \ in the code which it will not find in the text file that it is looking for, because i am looking for   <iabc-type="ppub">   instead of
 "<iabc-type=\"ppub\">"  any ideas on what i can put into the data base field to stop these \ from being returned every time it hits a " mark
Comment
Watch Question

Imran Javed ZiaConsultant Software Engineer - .NET Architect
CERTIFIED EXPERT

Commented:
Hi,
In c# back slash \ is escape sequence speifier. and double qoutation " is special character too.
if you need \ then specify \\ twice or use @ to make string to be used as it is.

thereofr check that your data in sql server has the related data. please also specify sql server verion and also add it in the zone
Thanks

Author

Commented:
not sure if its a sql server problem or a c# return problem
in the field in the sql server 2005 table i have the text
<iabc-type="nlm-ta">    
but after i read in the field by a  dt = readrec("select * from tblSearchTerms");
the returned string is "<iabc-type=\"nlm-ta\">    
and i need to get rid of the \ in the returned string, so either i need to take it out in the field or the returned string
also using studios 2005

Author

Commented:
you cannot use string replace because it does not like the \ in the function
sqlstringtemp = sqlstringstart.Replace("\", "");
wil not comnpile
Imran Javed ZiaConsultant Software Engineer - .NET Architect
CERTIFIED EXPERT

Commented:
then change your data in sql server as
<iabc-type=\"nlm-ta\">

or use following in c#
sqlstringtemp = sqlstringstart.Replace("\"", "\\\"");

Author

Commented:
sqlstringtemp = sqlstringstart.Replace("\"", "\\\"");
line changes to which is not workable
<iabc-type=\\\"nlm-ta\\\">

<iabc-type=\"nlm-ta\">   in the data base returns
<iabc-type=\\\"nlm-ta\\\">
which also is no good as i need to get rid of the \ not increase the numbers for the string
Consultant Software Engineer - .NET Architect
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
yes you were right when i run and not worry about them the code woks just fine bit of a furphy
thanks for the imput
posted the points for how much input you put into the question
thanks
garry

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.