Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a string like

output="'TransactionSourceID !='8' and GeneralLedger_SubTransactionType_CnfgLocale.SubTransactionType != '1'";


I need to remove the single quote before TransactionSourceID alone.

How do I do it ?

I tried

C#
if(output.Contains("'TransactionSourceID"))
                            output.Replace("\'TransactionSourceID","TransactionSourceID");


and

C#
if(output.Contains("'TransactionSourceID"))
                            output.Replace("'TransactionSourceID","TransactionSourceID");


But it didn't work.

I cant use index of the character because the length of the string and the position of "TransactionSourceID" may vary.

Any solutions ??
Posted
Updated 21-Oct-13 1:29am
v4

Quote:
if(output.Contains("'TransactionSourceID"))
output.Replace("\'TransactionSourceID","TransactionSourceID");


That should be:
C#
if(output.Contains("'TransactionSourceID"))
  output = output.Replace("\'TransactionSourceID","TransactionSourceID");

or simply:
C#
output = output.Replace("\'TransactionSourceID","TransactionSourceID");
 
Share this answer
 
v2
If you mean by "didn't work" that your changed string wasn't available via the output variable, then just try to assign it:
C#
output = output.Replace(YourCode);


"[String.Replace] does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of oldValue are replaced by newValue." (from the linked MSDN page).
 
Share this answer
 
v2
Comments
Rob Philpott 21-Oct-13 7:36am    
Spot on!
Divakar Raj M 21-Oct-13 7:37am    
Ya it works.. Thanks a lot !! :-)
Nandakishore G N 21-Oct-13 8:04am    
good answer. My 5..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900