I'm trying to remove whitespace and trailing white space from right and left side of my string in DB.
Note how the current results looklike:
Note the string named:
*excellent-purchase*
When I fetch it in my C# application like this:
ctx.Users.ToList();
The output for this string that I get is:
\t*excellent-purchase*
I need to remove this "\t" sign from my C# application either on DB level or inside the C# application.
The way I've tried it is like doing it is like this:
UPDATE
TableName
SET
ColumnName = LTRIM(RTRIM(ColumnName))
But I still get this \t sign in my C# app...
How can I fix this?
Edit:
guys I still have a weird characther like this:
"nl_holyland*555*
And in the C# App it looks like:
\"nl_holyland*555*
Theres an extra \ with this solution like
You can try it:
string value= Regex.Replace(value, #"\t|\n|\r", "");
You might want to try the following:
UPDATE
TableName
SET
ColumnName = LTRIM(RTRIM(REPLACE(ColumnName,char(9),'')))
You can use the Replace also:
UPDATE
TableName
SET
ColumnName = REPLACE(ColumnName, ' ', '')
Related
I am trying to implement a search function that allows the user to search by product tag. The problem is some of the tags are in different formats, like some have spaces and others don't.
At the moment I'm using WHERE modelNumber LIKE '" + '%' + number + '%' + "';"; This will get me the tag if they only fill in some of the tag name, but this won't work if the tag name includes a space but the user does not enter one.
My idea was create a char array with the chars in the search, so I'm wondering if there is a way to check if the SQL column entry contains each character in the way.
Thanks in advance.
You can use Contains to check for space characters:
"abc defg".Contains(' '); // True
There is also Trim, TrimEnd, and TrimStart depending on what you are trying to do.
Hy I have an application that gets his data pushed now from a other system. To communicate this with an api the , needs to be removed from the string.
eg:
var AMOUNT_INPUT txt_bedrag.txt = 12,30
var AMOUNT_INPUT txt_bedrag.txt = 1230 /*this is the expected result*/
I have tried:
I tried to remove the , char but that did not work.
How can i fix this so the users dont need to manualy remove the , character.
If you just want all the commas out you can use String.Replace() on it:
var cleanString = textbox.Text.Replace(",","")
I have a slight problem in that I am passing several SQL Server Like queries (which I don't have control over) in my .Net application and I need to escape some of the characters to make them literals for the database.
For example, suppose the field I am trying to query looks something like:
This_is [a] long_text field with [literal] characters in it
And my query looks something like this:
SELECT * FROM [MyTable] where [MyField] Like 'This_% [literal]%'
Now, this should get that data, the challenge is that the _ and [ characters are not seen by SQL Server as the literal characters, so I have to update my query to:
SELECT * FROM [MyTable] where [MyField] Like 'This[_]% [[]literal]%'
And then it works.
So, my question is that I would like to write a VB.Net function that uses RegEx to find the Like part of the statement and then to replace the characters.
Something along the lines of:
Public Function ConvertQuery(strSQL as string)
... Some kind of Regex that searches for the word "Like"
and then takes everytihng between the 2 "'" characters
Then replaces the "_" with "[_]" and "[" with "[[]"
Return ChangedString
End Function
I know I am giving REALLY bad details, I know what i want, I just can't figure out how to do it with RegEx.
ALSO, if there is a smarter way to do this with SQL Server Like statments, please also let me know!!!
Thanks!!
Seeing that C# tag, I assume you are OK with an answer in C#.
string input = "This_is [a] long_text field with [literal] characters in it";
var output = Regex.Replace(input, #"[_\[]","[$0]");
EDIT
string input = "SELECT * FROM [MyTable] where [MyField] Like 'This_% [literal]'";
var output = Regex.Replace(input, #"(?<=Like[ ]*\'.+?)[_\[]", "[$0]");
I am using FreeTextBox control
in asp.net.When I am getting its HtmlStrippedText in my code I am getting the String without HTML tags.Now how can I get the new line character from this String i.e. I want to Replace All the NewLine characters with Special Symbol "#".
Got the Solution:
Got the HtmlStrippedText in String str and then got replace it like this:
char enter=(char)111;
temp= str.Replace(enter+"", "\n");
If it is anything like the base ASP:TextBox, you can just grab the string from the text property and do something like
var test = txtYourControl.Text.Replace(Environment.NewLine, "#");
This will vary between browsers (perhaps even between the operating systems on which the browser is running). More on newline definitions here.
I have found the most reliable option to be to search and replace "\n" rather than Environment.NewLine which is "\r\n" in a Windows environment.
string text = this.txtField.Text.Replace("\n", "#");
HtmlStrippedText is used to get the plain text
You should use the text property of freetextbox control
u can remove new line using this code.
lblTitle.Text = txtFreetextbox.Text.Replace("<br>","#");
Click this link
http://freetextbox.com/docs/ftb3/html/P_FreeTextBoxControls_FreeTextBox_Text.htm
I'm trying to replace ' with its HTML entity reference using the String.Replace function. So a'a becomes a’a which is correct, but if I try to make the inverse (from the string above back to a'a) the output is always a’a.
I've noticed that if I try to replace only the code #8217; without the & character everything works fine, so maybe that the & character is a part of the problem.
This code works fine:
string s0 = "a'a";
string s1 = s0.Replace("'", "’");
string s2 = s1.Replace("’", "'");
Could you give us more information?
I don't know whats your problem, this little code works just perfect:
String test = "a’a";
Console.WriteLine(test.Replace("’", "'"));
I think its is string delimiters i.e ",' are interrupting normal string delimiters.