I'm trying to remove certain characters.
At the moment I have output like cityname district
but I want to remove cityname
.
SELECT Ort FROM dbo.tblOrtsteileGeo WHERE GKZ = '06440004'
Output:
Büdingen Aulendiebach Büdingen Büches Büdingen Calbach Büdingen Diebach Büdingen Dudenrod Büdingen Düdelsheim
Desired output:
Aulendiebach Büches Calbach Diebach Dudenrod Düdelsheim
You can remove a character from a Python string using replace() or translate(). Both these methods replace a character or string with a given value. If an empty string is specified, the character or string you select is removed from the string without a replacement.
Using translate(): translate() is another method that can be used to remove a character from a string in Python. translate() returns a string after removing the values passed in the table. Also, remember that to remove a character from a string using translate() you have to replace it with None and not "" .
The idea is to use the deleteCharAt() method of StringBuilder class to remove first and the last character of a string. The deleteCharAt() method accepts a parameter as an index of the character you want to remove.
The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.
You can use Replace
function as;
REPLACE ('Your String with cityname here', 'cityname', 'xyz') --Results 'Your String with xyz here'
If you apply this to a table column where stringColumnName, cityName both are columns of YourTable
SELECT REPLACE(stringColumnName, cityName, '') FROM YourTable
Or if you want to remove 'cityName'
string from out put of a column then
SELECT REPLACE(stringColumnName, 'cityName', '') FROM yourTable
EDIT: Since you have given more details now, REPLACE
function is not the best method to sort your problem. Following is another way of doing it. Also @MartinSmith has given a good answer. Now you have the choice to select again.
SELECT RIGHT (O.Ort, LEN(O.Ort) - LEN(C.CityName)-1) As WithoutCityName FROM tblOrtsteileGeo O JOIN dbo.Cities C ON C.foo = O.foo WHERE O.GKZ = '06440004'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With