Replace function - special characters
Hi All,
If my column is encountering special characters I would like to replace with blank. Special characters may vary from record to record. Sometimes it is @ sometimes $,!,,$,^,<,&,<,>,?,",{,},+,_,),(.
Do we have any function same like replace that can replace all special characters, whatever it encounters with required value?
- please mark correct answers
Take a look at this article
T-SQL:
How to Find Rows with Bad Characters
and check See Also section in that article for more articles on that topic.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Thanks Naomi
- please mark correct answers
Similar Messages
-
Replace all special characters in a String with underscore
I have a String which contains some special characters even(!,$,@,*....).
I need to replace all the special characters with _ in my String. I do have an idea of using String.replace() and analogous forms, but I would be thankful if anyone can suggest me of a better and an efficient way.
regards,
fun_oneKaj,
Thx for your earnest reply. I did have a peep into the API on this method. But the regular expression that I need to use here was beyond my understanding. It did specify some regex that I put to use (something like myString("\D","_"), assuming that I need to replace all non-digit characters ), but it really did not help me getting the result.
Would you spare some code for me reg. the usage of regular expressions in such a scenario?
cheers,
fun_one -
How to replace XML special characters using Xpress e.g. ' = '
Hellos
I need to write some XML built from resource data.
The resource data strings can contain anything e.g. & ' " < and > characters.
How do I replace these characters with the strings & ' " etc.... from within Xpress?
I try something like:-
<set name='testchar'>
<switch>
<ref>thisLetter</ref>
<case>
<s>'</s>
<s>'</s>
</case>
<case>
<s>"</s>
<s>"</s>
</case>
<case default='true'>
<ref>thisLetter</ref>
</case>
</switch>
</set>
But when saved the <s>'</s> gets saved as <s>'</s>
Is this impossible with Xpress forcing me to invoke my own Java class? (which is a pain to do because of internal politics re restarting of App Server).Hmmmm seems there is transformation in this set up too.
What I am trying to do is to parse a string which may or may not contain XML special characters into an XML acceptable string.
e.g. transform the surname O'Connor into O&apos ;Connor (with no embedded blank)
I wish to write a rule which uses XPress language to achieve this.
I want to convert the character ' into the string &apos ; (with no blank between apos and ;) and similar for the other XML specials.
Is this possible? -
Replacement of special characters through hex-code
Hi,
I create a xml-output via SYS_XMLTYPE- and XML_ELEMENT-functions. In the coulumn values I select special XML-Characters like the ampersand will be automatically replaced through their quivalent Escape code (&) - But our special german characters (ä, ü, ö, ß) won't be replaced. Is there a function to replace them or do I have to write my own function?
Bye,
JensHi Mark,
now I have a problem with the replacement (You must replace $ through an ampersand to understand the code, the ampersand would be automatically replaced)
The following query:
SELECT XMLELEMENT( "city", a.city,
XMLELEMENT( "company", a.company )
) AS XML_DATEN
FROM (
SELECT 'München' AS CITY, 'MCM' AS COMPANY
FROM dual
UNION
SELECT 'Hamburg' AS CITY, 'P$C' AS COMPANY
FROM dual
) a
returns
<city>Hamburg<company>P$amp;C</company></city>
<city>München<company>MCM</company></city>
Ok, that's fine. The XMLELEMENT function automatically replaces the ampersand. But the "ü" do I have to replace for myself.
But when I do it:
SELECT XMLELEMENT( "city", REPLACE( a.city, 'ü', '$#'||ASCII('ü')||';' ),
I got the following:
<city>M$amp;#252;nchen<company>MCM</company></city>
And not:
<city>M$#252;nchen<company>MCM</company></city>
How can I solve this problem? -
Replace Special Characters in a string + XQUERY
Hi All,
I am using the following replace function to replace the special characters in my XQUERY.
*replace($string1, '[&"-*;-`!|:,¿/{}@#$%^*~()_+-]', ' ')*
Fortunately it is replacing all the special characters. But the only problem here is it is even replacing capitol letters in to spaces, which I don't want.
Please help me out!!Hi
<<< What did u change >?> I dont see any change with the Regex ? >>
if you observe in the modified function, he just removed (*) inside the replace funtion.
Thanks
Shankar AUNV -
Replace special characters in String
Dear Guru ,
Does SAP provide the standard function that can replace the special characters in String ?
For example :
I have one template string : " & & & & & output(s) have not been processed yet ! " and five parameters : "P1" , "P2" , "P3" , "P4" , "P5" .
And i would like to apply all parameters into the string to replace the "&" character . Is it possibile ?
My idea is sourcing from the Message String that in tcode : SE91 .
Thanks .
Best Regards,
Carlos ZhangHi Carlos,
I think instead of a standard FM you can write a one line command to do this job.
E.g.
constant: str1 type string value 'output(s) have not been processed yet ! '.
data: var1 type c,
var2 type c,
var3 type c,
var4 type c,
str type string.
concatenate var1 var2 var3 var4 str1 into str separated by space.
So str will have the final value.
Thanks,
Mainak -
How to replace special characters in Purchase order item text in ECC 6.0
Hi All,
Now i am working in ECC environment.
I am unable to replace the special characters in the PO short text for example take the following text.
Job#Burst Fire 3930-00092#Heater Control
here i want to replace # symbol with space.
i used replace all occurences, find , transfer, overlay keywords to replace thta special characte but it is not replacing that character.
i used replace_string FM also.it is also not working.
please help me out in this. points will be rewarded.Hi Praveena,
what replacement(s) did you try?
Please
replace all occurrences of
CL_ABAP_CHAR_UTILITIES=>newline
CL_ABAP_CHAR_UTILITIES=>cr_lf
CL_ABAP_CHAR_UTILITIES=>form_feed
CL_ABAP_CHAR_UTILITIES=>horizontal_tab
CL_ABAP_CHAR_UTILITIES=>vertical_tab
CL_ABAP_CHAR_UTILITIES=>backspace
CL_ABAP_CHAR_UTILITIES=>minchar
CL_ABAP_CHAR_UTILITIES=>maxchar
minchar is HEX u201900u2018 in non-Unicode systems, U+0000 in Unicode systems
maxchar is HEX Xu2018FFu2018 in non-Unicode systems, U+FFFD in Unicode systems
If it still does not help, check the remaining # characters in debugger, switching to hex mode: Then you may see what it is.
Regards,
Clemens -
Search & Replace special characters?
Is there a way to search & replace for special characters, such as paragraph or tab marks?
Not in Pages 5.2 because Apple made it new and improved.
However both Pages '08 and Pages '09 can search on invisible characters, precisely because they are not new and improved.
Peter -
HTML Editor - converting "special characters" into entities
Hi everyone,
I'm currently in the middle of formatting my wife's novel into 'clean' html so I can use Calibre to create a well formatted epub/mobi/etc.
I've read that TextMate on Mac includes a function to "Convert Selection to Entities excluding Tags". In other words it will replace all special characters (ellipses, copyright sign, etc) with the html entities.
I'm currently using Kate and I can't seem to find anything similar. Is anyone aware of any linux editors with the same function?
Thanks for the help!ctarwater wrote:Encoding is already UTF-8 but I'm trying to make these docs as "universal" as possible and I've read that little things like replacing quotation marks and other symbols with their html entities is a good step in that direction.
In situations with multiple encodings this might be the case, but the XML spec requires UTF‐8 support at minimum and defaults to it when the encoding is not declared. All XML parsers can deal with UTF‐8.
In fact, replacing UTF‐8 characters with entities is less portable in XML. This is because the available entities are defined by the doctype, and XML only supports five by default (<, >, ", &, and '). Things like … are defined in the HTML and XHTML doctypes, but not in other dialects of XML. This used to bite RSS pretty hard (probably still does), because people assumed the entities were available everywhere when they’re really not. EPUB and Mobi are based on XHTML, but other formats might use other XML dialects. -
Sending special characters to non-unicode non-sap system: user exit
Hello All,
We are sending data from a SAP unicode system to a non-sap non-unicode system via IDOC. The idoc is standard idoc GLMAST which contains gl account information.
Some text fields contained in this idoc can contain special Polish characters. If they are sent unchanged to the non-unicode system, they give problems in the destination system.
What we would like to do is to build a user exit to convert these special characters, for example : 'é' becomes 'e', ....
We used enhancement object ALE00001, function EXIT_SAPLBD11_001 and implemented it, but it seems this exit is not called. Can this user exit be used for this functionality?
We also tried to change in SM59 the type of system of the destination to non-unicode, so that SAP replaces those special characters by #. But, than the error 02. Codepage not found is given in the idoc. Note: the link to the external system is not set up yet, so no actual connection is possible. Is this why we receive this error, and will this functionality work in the end with a non-sap system?
Thanks for helping.
Kind Regards,
Bart PelsmaekersI faced this problem in many project i implement below logic.
DATA: c_splchar(2) VALUE '90',
c_defaultchar(1) type c VALUE '#'.
You have to move one by one character to this function module
CALL FUNCTION 'URL_ASCII_CODE_GET'
EXPORTING
trans_char = spl_char
IMPORTING
char_code = spl_code.
All non unicode(Better you check) are always greater than 90.
if spl_code is gt c_splchar.
move c_defaultchar to c_splchar.
endif.
"Reward points if usefull"
Thanks,
Narayan -
How to Handle Special Characters in PI7.1
Hi Team,
I need to handle some special characters like <,>,& etc.. from WS Adapter to CRM in PI 7.1.
http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/9420 [original link is broken]
By using the above blog i had implemented the Java Code as
public void execute(InputStream in, OutputStream out){
try{
int read_data;
while((read_data = in.read()) != -1){
if (read_data == '&'){
out.write("&".getBytes());
}else if (read_data == '>'){
out.write(">".getBytes());
}else if (read_data == '<'){
out.write("<".getBytes());
}else if (read_data == '/'){
out.write("⁄".getBytes());
}else if (read_data == '\''){
out.write("'".getBytes());
else { out.write(read_data);
out.flush();
} catch (Exception e){}
I had added this class file in Operational Mapping.
It is working if we have only one IF condition for & in while
Any suggestion
Thanks
SriramHi Ramesh,
Thanks for your inputs, I have tried your code but it is not working. The error message stays the same.
Dear Stephane,
To describe the error more, the requirement is the payload coming from source through WS Adapter consists of the special characters <, > , & which are basic sematics of XML syntax. I need PI to process this payload with special characters and successfully transfer it to target CRM system. I have created the Java class with code (ref: Blog 9420) as stated earlier and added this class to my existing Operation Mapping. I am expecting the java mapping to replace the special characters in payload like < with ">" . So as the case with the other characters >,&,'
After activaton of my operation mapping, I triggered the test message with Soap UI client and I could able to get a successful mapping only When I put the logic for &ersand symbol only. However when I am trying to add the logic for > or < or ' the mapping is failing . I am using UTF-8 encoding across the source and PI enviroments.
Sample SOAP message :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:abcabca.com">
<soapenv:Header/>
<soapenv:Body>
<urn:MT_ABCDEFG_Req>
<activity>
<id/>
<type>ZEMA</type>
<actionType>C</actionType>
<firewall>10000003</firewall>
<subject>small > < attachment test</subject>
<location/>
<startDate>2010-07-08T10:53:31.000Z</startDate>
<endDate>2010-07-08T10:53:31.000Z</endDate>
<mainClient>1000319</mainClient>
<mainContact>1000003</mainContact>
<isConfidential>false</isConfidential>
<summary/>
<fullText>test body - small.txt</fullText>
<owner>1000021</owner>
<from>ABCDEDF</from>
<sendTo>emailaddress</sendTo>
<copyTo/>
<keywords/>
<referenceId/>
<createdBy>1000021</createdBy>
<additionalContacts/>
<additionalClients/>
<additionalParticipants/>
<status>A0008</status>
<attachments>
<fileUrl>20100708110053-XXXXXXXXX</fileUrl>
<fileName>small.txt</fileName>
</attachments>
<attachments>
<fileUrl>20100708110053-XXXXXXXXX</fileUrl>
<fileName>EMail 2010-07-08.pdf</fileName>
</attachments>
</activity>
</urn:MT_ABCDEFG_Req>
</soapenv:Body>
</soapenv:Envelope>
Output on the SOAP UI client for the above request:
<!--see the documentation-->
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<SOAP:Fault>
<faultcode>SOAP:Server</faultcode>
<faultstring>Server Error</faultstring>
<detail>
<s:SystemError xmlns:s="http://sap.com/xi/WebService/xi2.0">
<context>XIAdapter</context>
<code>ADAPTER.JAVA_EXCEPTION</code>
<text>com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.engine.interfaces.messaging.api.exception.MessagingException: XIServer:NO_MAPPINGPROGRAM_FOUND:
at com.sap.aii.adapter.soap.ejb.XISOAPAdapterBean.process(XISOAPAdapterBean.java:1160)
at sun.reflect.GeneratedMethodAccessor342.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(
What do you think where I am doing the wrong?
Sriram -
How to handle special characters in NWDI
Dear All
I am trying to update the Description from JSP form. Through JCO we are calling the RFC of ABAP. We are passing these description from Java to RFC of ABAP and this RFC update the text in Database.
We have noticed that if there is some special character in description like as : or , complete description is not getting updated in to the SAP database.
Can anyone help me how to handle these special characters in Java. There may be N number of special characters. We want to generalize it. We want to replace these characters by s and z respectively.
For example : We want to update this description.
APPLERR H'4301 H'FA03 H'254C na Zagreb TC4 rijeen je cleaning procedurom, te je i kroz CSR odgovoreno da trap korekcija N01TCADG-0052 u bloku UPDC vie nije potrebna, te se moe izbaciti (AP143).
Uspjeno su zavrene HR17/CN-A3 FOA-e na tranzitnom nivou, te slijedi roll-out u dva termina 12/13.04 i 19/20.04. ETK je na sastanku isporučio SW, te ALEX i mini PLEX za sve objekte.
AP147. Poslati finalnu dokumentaciju za uvođenje paketa (implementacijsku instrukciju i sve popratne datoteke).
WHile updated text is as follows :
APPLERR H'4301 H'FA03 H'254C na Zagreb TC4 rije
N01TCADG-0052 u bloku UPDC vi
Uspje
sastanku isporu
AP147. Poslati finalnu dokumentaciju za uvo
Regards
BhavishyaHi Bhavishya,
Apparently your SAP database isn't configured to support Unicode. That would be the first solution to your problem, but I can imagine it's a bit drastic to convert your DB.
A second solution would be to encode the input description to ASCII before storing it in the database. When reading from the database, decode again to Unicode. This way, no information is lost. A suitable encoding would be Base64. e.g.
String description = "unday ebra";
String descriptionBase64 = new sun.misc.BASE64Encoder().encode(
description.getBytes("UTF-8")); // ""
// store descriptionBase64 in the DB
// later, when reading descriptionBase64 from the DB
String description2 = new String(
new sun.misc.BASE64Decoder().decodeBuffer(descriptionBase64), "UTF-8");
Instead of using Sun's implementation, a better alternative is to use the open source implementation
org.apache.commons.codec.binary.Base64 from Commons Codec .
The 3rd approach is indeed to normalize the description by replacing all special characters with their ASCII equivalent. A rather easy solution is as follows:
String description = "unday ebra";
String descriptionNormalized = sun.text.Normalizer.normalize(
description, sun.text.Normalizer.DECOMP, 0).replaceAll(
"[^p{ASCII}]", "");
sun.text.Normalizer decomposes the string, e.g. "éàî" becomes "e´a`i^", after which non-ASCII characters are being removed using a regular expression.Again, note that it's usually a bad idea to use sun.* packages, see note about sun.* packages. The above code only works with J2SE 1.4 and J2SE 5.0, but it breaks in J2SE 6.0 (where
java.text.Normalizer became part of the public API ;-). A good open source implementation can be found here: ICU4J (com.ibm.icu.text.Normalizer).
Kind regards,
/Sigiswald -
Finding special characters in a string
Hi all, I'm using Oracle 10g.
I have a column name with special characters. how can i replace the special characters in the column with space and no space depending on the special character. please see the example below. can i use REGEXP_REPLACE?
create table
create table sample_test (
Name VARCHAR2(20 BYTE))insert table
insert into sample_test values ('O''NEIL')
insert into sample_test values ('B.E.VICTOR')
insert into sample_test values ('WILLIAM,L')
insert into sample_test values ('MARY-ANNE')
insert into sample_test values ('VON_ANCKEN')
insert into sample_test values ('BROWN;L')i would like the output as follows
Special Character Name Expected Name Remarks
Single Quotes O'NEIL ONEIL Remove quotes and no space
Dot B.E.VICTOR B E VICTOR Replace with space
Comma WILLIAM,L WILLIAM L Replace with space
Hyphen MARY-ANNE MARY ANNE Replace with space
Underscore VON_ANCKEN VON ANCKEN Replace with space
Semi Colon BROWN;L BROWN L Replace with space Please advise.
Thanks
BobA simple solution without regexp usage:
-- Test Data
with sample_test as
select 'O''NEIL' name from dual union all
select 'B.E.VICTOR' name from dual union all
select'WILLIAM,L' name from dual union all
select'MARY-ANNE' name from dual union all
select'VON_ANCKEN' name from dual union all
select'BROWN;L' name from dual
-- Query:
select name old_name,
translate(replace(name,'''',''),'.,-_;',' ') new_name
from sample_test;Explanation:
REPLACE deletes the quote
TRANSLATE replaces dot, comma, hyphen, semicolon and underscore -
Replacement of Spl Characters- REPORT
Hi All,
I want to replace some special characters like & with 'and' # with num. etc in my report.
I tried using REPLACE ALL OCCURANCE OF but this gives performance issue and the report takes a long time to be executed.
Moreover i cannot specify offset and length since the special characters can come anywhere.
Please help me in this. Points will be rewarded for all useful inputsHi,
Please select required solution from one of the followings:
REPLACE by Pattern
Replaces strings in fields with other strings using a pattern.
Syntax
REPLACE [ FIRST OCCURENCE OF | ALL OCCURENCES OF ] <old>
IN [ SECTION OFFSET <off> LENGTH <len> OF ] <text> WITH <new>
[IGNORING CASE|RESPECTING CASE]
[IN BYTE MODE|IN CHARACTER MODE]
[REPLACEMENT COUNT <c>]
[REPLACEMENT OFFSET <r>]
[REPLACEMENT LENGTH <l>].
In the string <text>, the search pattern <old> is replaced by the content of <new>. By default, the first occurrence of <old> is replaced. ALL OCCURENCES specifies that all occurrences be replaced. In the fields <old> and <new>, trailing spaces in C fields are ignored, but included in <text>. The SECTION OFFSET <off> LENGTH <len> OF addition tells the system to search and replace only from the <off> position in the length <len>. IGNORING CASE or RESPECTING CASE (default) specifies whether the search is to be case-sensitive. In Unicode programs, you must specify whether the statement is a character or byte operation, using the IN BYTE MODE or IN CHARACTER MODE (default) additions. The REPLACEMENT additions write the number of replacements, the offset of the last replacement, and the length of the last replaced string <new> to the fields <c>, <r>, and <l>.
REPLACE by Position
Replaces strings in fields with other strings by position.
Syntax
REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].
[IN BYTE MODE|IN CHARACTER MODE].
ABAP searches the field <c> for the first occurrence of the first <l> characters in the pattern <str1> and replaces them with the string <str2>. In Unicode programs, you must specify whether the statement is a character or byte operation, using the IN BYTE MODE or IN CHARACTER MODE (default) additions.
Please rewrad points if helpful. -
FTP ADAPTER: How to handle Special characters
Hi All,
We are running into issues with special characters while fpt'ing the file using FTP adapter.
ex: japanese characters '東邦チタニウム株式会社' would look as '???????????' in the transferred file.
The following steps are involved in the process.
1. Reads the data from a database.
2. Constructs an XML object.
3. Transforms the data into ftp msg.- In this step the spl. characters are fine
4. FTP's the msg.
5. The file on FTP server has issues.
Tried to change the file type to binary, UTF-8 etc.. but nothing worked.
Any help/pointers will be highly appreciated.
Thanks in advance.Hi Bhavishya,
Apparently your SAP database isn't configured to support Unicode. That would be the first solution to your problem, but I can imagine it's a bit drastic to convert your DB.
A second solution would be to encode the input description to ASCII before storing it in the database. When reading from the database, decode again to Unicode. This way, no information is lost. A suitable encoding would be Base64. e.g.
String description = "unday ebra";
String descriptionBase64 = new sun.misc.BASE64Encoder().encode(
description.getBytes("UTF-8")); // ""
// store descriptionBase64 in the DB
// later, when reading descriptionBase64 from the DB
String description2 = new String(
new sun.misc.BASE64Decoder().decodeBuffer(descriptionBase64), "UTF-8");
Instead of using Sun's implementation, a better alternative is to use the open source implementation
org.apache.commons.codec.binary.Base64 from Commons Codec .
The 3rd approach is indeed to normalize the description by replacing all special characters with their ASCII equivalent. A rather easy solution is as follows:
String description = "unday ebra";
String descriptionNormalized = sun.text.Normalizer.normalize(
description, sun.text.Normalizer.DECOMP, 0).replaceAll(
"[^p{ASCII}]", "");
sun.text.Normalizer decomposes the string, e.g. "éàî" becomes "e´a`i^", after which non-ASCII characters are being removed using a regular expression.Again, note that it's usually a bad idea to use sun.* packages, see note about sun.* packages. The above code only works with J2SE 1.4 and J2SE 5.0, but it breaks in J2SE 6.0 (where
java.text.Normalizer became part of the public API ;-). A good open source implementation can be found here: ICU4J (com.ibm.icu.text.Normalizer).
Kind regards,
/Sigiswald
Maybe you are looking for
-
How can I create a one-click download for a PDF file?
I want to have several PDF files on the website ... for downloading. How do I create a one-click download button? for those who don't know about control-right-clicking to download something? Does such a possibility exist? Ben
-
Can't get my ipod out of Disk Mode
My iPod froze and was not being recognized by my computer. I got it into Disk Mode and now the computer is recognizing it but I can't get it out of disk mode. Any suggestions? Thanks!!!
-
DOC Splitting in New GL and Profit center accounting activation
Dear All, I am in a dilemma regarding the following - We are activating doc splitting with profit center and segment as characteristics. 1) While maintaining Controlling area settings(OKKP) - do we need to activate "Profit Center Accounting" componen
-
Itunes cant find "iTunes" folder in Windows XP Professional
after installation of iTunes 4.7.1 without error messages, iTunes wont start up. Keeps giving error message: The folder "iTunes" cannot be found or created and is required. The default location for this folder is inside the "My Music" folder. On my w
-
Can a non standard font cause Publisher to crash? we have had several cases of publisher crashing when our team changes text formatting and header fonts. They use non standard design fonts