Replace Non-Numeric Characters with a Numeric Character in a String
Hi Guys,
I need to replace all the non-numeric characters (including embedded blanks & hyphen) in a string to a numeric character '1'.
The trailing blanks should not be replaced.
e.g. "P22233344455566" should be changed to "122233344455566"
& "49-1234567 " should be changed to "4911234567 "
Please help.
Use [replace|http://help.sap.com/abapdocu_70/en/ABAPREPLACE_IN_PATTERN.htm] with a regular expression to translate any non-numeric character (i.e. any character not between 0 and 9) to 1:
REPLACE ALL OCCURENCES OF REGEX '[^0-9]' IN value WITH '1'.
Cheers, harald
p.s.: In older releases [translate|http://help.sap.com/abapdocu_70/en/ABAPTRANSLATE.htm] would also do the trick, but is more lengthy, because one would need to specify each individual character that should be replaced, e.g.:
TRANSLATE value TO UPPER CASE.
TRANSLATE value USING
' 1_1-1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1'.
Similar Messages
-
Replacing non-ASCII characters with HTML charcter references
Hi All,
In Oracle 10g or greater is there a built-in function that will convert a string with non-ASCII characters like this
a b č 뮼
into an ASCII string with HTML character references like this?
a b & # x 0 1 0 D ; & # x B B B C ;
(note I had to include spaces between each character in the sample code for message to prevent the forum software from converting my text)
I tried using
utl_i18n.escape_reference( val, 'us7ascii' )
but for some reason it returns
a b c & # x B B B C ;
Note how it converted the Western European character "č" to its unaccented counterpart "c", not "& # x 0 1 0 D ;" (is this a bug?).
I also tried a custom solution using regexp_replace and asciistr (which I can't include here because the forum software chokes on it) but it only returns the correct result for values <=4000 characters long. Unfortunately asciistr doesn't appear to accept CLOB values larger than 4000 characters. It returns an error message like
(ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 30251, maximum: 4000) ).
I'm looking for a solution that works on CLOB data of any size.
Thanks in advance for any insight you can provide.
Joe FudaSo with that (UTF8) in mind, let's take another look.....
As shown below, I used a AL32UTF8 database.
Note: I did not use a unicode capable tool for querying. So I set console mode code page to 1250 just to have č displayed properly (instead of posing as an è).
Also, as a result of using windows-1250 for client character set, in the val column and in the second select's ncr column (iso8859-1), è (00e8) has been replaced with e through character set conversion going from server back to client.
Running the same code on a database with a db character set such as we8mswin1252, that doesn't define the č (latin small c with caron) character, would yield results with a c in the ncr column.
C:\>chcp 1250
Aktuell teckentabell: 1250
C:\>set nls_lang=.ee8mswin1250
C:\>sqlplus test/test
SQL*Plus: Release 11.1.0.6.0 - Production on Fri May 23 21:25:29 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the OLAP option
SQL> select * from nls_database_parameters where parameter like '%CHARACTERSET';
PARAMETER VALUE
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16
SQL> select unistr('\010d \00e8') val, utl_i18n.escape_reference(unistr('\010d \00e8'),'us7ascii') NCR from dual;
VAL NCR
č e c e
SQL> select unistr('\010d \00e8') val, utl_i18n.escape_reference(unistr('\010d \00e8'),'we8iso8859p1') NCR from dual;
VAL NCR
č e &# x10d; e <- "è"
SQL> select unistr('\010d \00e8') val, utl_i18n.escape_reference(unistr('\010d \00e8'),'ee8iso8859p2') NCR from dual;
VAL NCR
č e č &# xe8;
SQL> select unistr('\010d \00e8') val, utl_i18n.escape_reference(unistr('\010d \00e8'),'cl8iso8859p5') NCR from dual;
VAL NCR
č e &# x10d; &# xe8;In the US7ASCII case, where it should be possible for all non-ascii characters to be escaped, it seems as if the actual escape step is skipped over.
Hope this helps to understand whether utl_i8n is usable or not in your case.
Message was edited by:
orafad
Fixed replaced character references :) -
Replace non numerics characters with 0
Hi,
Can someone help me out with this?
I basically need to check my column value.
In case thr is an occurence of any non numeric character ,I need to replcae it with a 0.
By non numeric I mean any character other than [0-9].
For example 'rte$36^r'
I would like to convert it o '00003600'.
Thanks in advance.There are several options, like TRANSLATE or REGEXP_REPLACE (only 10g):
WITH t AS (SELECT 'rte$36^r' col1
FROM dual
SELECT t.col1
, REGEXP_REPLACE(t.col1, '[^0-9]', '0') col1_new1
, TRANSLATE(t.col1, '0123456789' || t.col1, '0123456789' || LPAD('0', LENGTH(t.col1), '0')) col1_new2
FROM t
COL1 COL1_NEW1 COL1_NEW2
rte$36^r 00003600 00003600C. -
How to replace non-alphanumeric characters with " " in a String?
Hi,
Anyone can help with this?
I guess I should use the replaceAll-method??I need to keep characters that are generally ok to
use in
sentences, like ".", ",", "!", and "-" and alsoall
digits and letters
(numbers and alphabetic characters).Add those characters to the pattern in that case. Add
them just before ]
but placing the '-' char as the last in the list. -
Replace non-english characters function
Hi folks,
I have a text which includes non english characters. Is there any trick, how can I replace those characters with "closest" english character?
Examples:
"Hytölä" to become "Hytola"
"Säynatsälo" to become "Säynatsälo"
etc ...
I was thinking about usage of REGEXP
select regexp_replace('Hytölä Säynatsälo ', '[^0-9A-Za-z]', '') from dual
but a pattern is not correct.
Any suggesitons?There is something that smells like a hack for me (source: replace characters with accent with their base letter)
However
with data as (
select 'Hytölä' str from dual
union all
select 'Säynatsälo' from dual
select
str
,utl_raw.cast_to_varchar2(nlssort(str, 'NLS_SORT=BINARY_AI')) nstr
,length(utl_raw.cast_to_varchar2(nlssort(str, 'NLS_SORT=BINARY_AI'))) l
from data
STR
NSTR
L
Hytölä
hytola
7
Säynatsälo
saynatsalo
11
Notice that change in length through an extra null bit at the end of the strings.
And the loss of the uppercase.
For this kind of questions it's helpful to know about the requirements. Why there shuóuld be a baseletter conversion? For search purposes for example.
not to forget the db characterset. -
Replacing non-ascii characters in String
I have a site where the user enters data in a rich text
editor (ktml4) that gets stored into a database (mysql). There are
non ascii characters getting into the data, I'm assuming that they
are copying and pasting from Word. Unfortunately in this situation,
changing that process isn't an option.
Currently, this is the only character that is causing me
problems:
http://www.zvon.org/other/charSearch/PHP/search.php?request=ffa0&searchType=3
I would just like to replace the non-ascii characters with a
space when I read them from the database. Something like:
#Replace(result.column, '\xffa0', ' ')#
However, I believe that code looks for the string "\xffa0",
not the character \xffa0.
Is there anyway to do this?quote:
Originally posted by:
BuckLemke
quote:
Originally posted by:
Dan Bracuk
rereplace might work.
Can you give an example of how to pass a non-ascii character
to REReplace?
Regular expressions are not my strength, but the approach I
was considering was, "if it's not an ascii character, make it a
space". Then you pass the entire string at once. -
Removing Non-numeric characters from Alpha-numeric string
Hi,
I have one column in which i have Alpha-numeric data like
COLUMN X
+91 (876) 098 6789
1-567-987-7655
so on.
I want to remove Non-numeric characters from above (space,'(',')',+,........)
i want to write something generic (suppose some function to which i pass the column)
thanks in advance,
MandipThis variation uses the like operators pattern recognition to remove non alphanumeric characters. It also
keeps decimals.
Code Snippet
CREATE FUNCTION dbo.RemoveChars(@Str varchar(1000))
RETURNS VARCHAR(1000)
BEGIN
declare @NewStr varchar(1000),
@i int
set @i = 1
set @NewStr = ''
while @i <= len(@str)
begin
--grab digits or (| in regex) decimal
if substring(@str,@i,1) like '%[0-9|.]%'
begin
set @NewStr = @NewStr + substring(@str,@i,1)
end
else
begin
set @NewStr = @NewStr
end
set @i = @i + 1
end
RETURN Rtrim(Ltrim(@NewStr))
END
GO
Code to validate:
Code Snippet
declare @t table(
TestStr varchar(100)
insert into @t values ('+91 (8.76) \098 6789');
insert into @t values ('1-567-987-7655');
select dbo.RemoveChars(TestStr)
from @t -
Replacing non latin characters
Hi experts,
i have to check some fields of non latin characters.
When the fields include some of non latin charcters I have to replace them
with an "Y".
Have somesone a code example for this case?
Thanks for help!
AlexThis should give you an Idea
WHILE p_faxno CA sy-abcde. " to check if varaible contains any abcde...Z
p_faxno+sy-fdpos(1) = 'Y'.
ENDWHILE.
CONDENSE p_faxno NO-GAPS -
Deleting/replacing non-alphabetic characters
I'd like to delete any non-anlphabetic characters in a given string, so I figured the following:
for (int i=0; i < aString.length(); i++){
if (!isAlpha(aString.charAt(i))){
char c = aString.charAt(i);
aString = aString.replace(c,' ');
}Which doesn't work, and I don't understand why. (Ideally like to delete this char c, but replacing it with whitespace will I think also do)
Anyone any suggestions?how about using regular expressions?
Here is an example using posix notation:
public class Repl
public static void main(String args[]){
String a = "Aghewuz2nknl7kj%\"dsk";
// here any non alpha char is replaced by a space
System.out.println(a.replaceAll("[^\\p{Alpha}]", " "));
}{code} -
Replace multiple space characters with a single space
Hi,
Oracle 11g R2.
Looking for a way to replace multiple space characters in a row with a single space. For example, the text "abc abc" should look like "abc abc". I tried toying with replace, but it only works for the case of 2 spaces. Need a solution for the cases where there could be 2 or more spaces.
select replace(column1, chr(32)||chr(32), chr(32)) from tableaHi,
If you had to do this without regular expressions, you could use:
SELECT REPLACE ( REPLACE ( REPLACE (str, ' ', '~ ')
, ' ~'
, '~ '
) AS new_str
FROM table_x;assuming there is some sub-string (I used '~' above) that never occurs right next to a space.
However, unless you're uisng Oracle 9 (or earlier, which you're not doing) you don't have to do this without regular expressions. As you can see, the way Solomon showed is much simpler. -
RegEx in TSQL - replace non-alphanumeric characters etc
Hi guys, I have this function in VB that I used in Access to replace all non-alphanumeric characters, including spaces and anything in brackets.
Public Function charactersonly(inputString As String) As String
Dim RE As Object
Set RE = CreateObject("vbscript.regexp")
RE.Pattern = "\([^)]+\)|[^\w]|_"
RE.Global = True
charactersonly = RE.Replace(inputString, "")
Set RE = Nothing
End Function
Now, I moved to SQL server and I'm writing scripts to do same thing.
How can I use RegEx in TSQL?
Only thing I will do is that function.As alternative
declare @string varchar(200)
set @string = 'gg$%^^&is%^& s2342jjk23&&({}e c76l232e+_+a#n/ c][#o''y#e'
select cast(cast((select substring(@string,n,1)
from numbers
where n <= len(@string)
and substring(@string,n,1) like '[0-9 ]' for xml path('')) as xml)as varchar(max))
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Encoding non english characters with utf 8 on jsp (Critical!!)
I am inserting hebrew characters from JSP into oracle db and everything is fine until this point. But when I try to retrieve the information from the database, the characters are not displayed properly (I get some garbage characters). I am sure that the data stored in the database is correct, but not sure why there is a problem in displaying the data in the JSP.
I came across a thread on TSS
http://www.theserverside.com/discussions/thread.tss?thread_id=28944
and followed the suggestions given there like having
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">and also this
<%
//Some JDBC and sql statement query UTF-8 data and then ...
String str = rs.getString("utf8_data");
str = new String(str.getBytes("ISO-8859-1"),"UTF-8");
%>
<%= str %>Now, the data getting displayed is partly correct, I mean to say, some characters are still coming as squares.
Any ideas will be of great help.even i doubt the database charset for this issue. But what I dont understand is how only certain hebrew characters are getting stored properly and why others are corrupted?
Also, can anyone let me know how i can view the Non-English characters present in the database directly, as TOAD is not able to display them -
I have a person that is called "josée".
I need "JOSEE" to be inserted into the database, not "JOSéE".
I also have a person called "jürgen".
I need "JURGEN" to be inserted into the database.
Is there a way to do this ?
(replace the non-ascii character by his corresponding ascii character)Thanks ebrian, I tried your suggestion:
SELECT VALUE, REGEXP_REPLACE(VALUE, '^[:ascii:]') FROM AUDIT_TAB_COLUMNS WHERE VALUE = '' ;
It sill leaves in the square unfortuneatly.
Dave -
SmartForms : Printing Non-English characters with SWIN output device?
I have a Japanese Text (entered in Unicode at So10) and I want to print it from my SmartForms application using SWIN device type.
I thought SWIN converted all the components into graphics before sending to printer. To my surprise, the Japanese text printed out as "########".
I even tried duplicate the SWIN output device to another output device and changed the character set to 4103 UTF-16LE Unicode / ISO/IEC 10646 but then the print process hang.
Anyone knows how to overcome the problem so that I can print Japanese with SWin output device?I have a Japanese Text (entered in Unicode at So10) and I want to print it from my SmartForms application using SWIN device type.
I thought SWIN converted all the components into graphics before sending to printer. To my surprise, the Japanese text printed out as "########".
I even tried duplicate the SWIN output device to another output device and changed the character set to 4103 UTF-16LE Unicode / ISO/IEC 10646 but then the print process hang.
Anyone knows how to overcome the problem so that I can print Japanese with SWin output device? -
Replacing occurance of characters with different columns
I am using SQL server 2012 . I have below resultset from the query . I want to replace first & with column2 and second & with column 3 . Both SSIS and Tsql work
column1 column2
column3
& created under the number & 3456134 49012345
Result I want is:
Column1
column2 column3
3456134 created under the number 49012345 3456134 49012345Can you explain your requirement in a better way?
Correct me if I'm wrong
Two '&' in col1 - should be replaced 1st & by col2 and 2nd by col3, if col1 or col2 is null it should not change col1.
why do you want to hardcode? Just run only the select statement on your table and see for the results
select isnull(Replace(ISNULL(STUFF(col1, CHARINDEX('&', col1), 1, isnull(col2, '&')),col1),'&',isnull(col3,'&')),col1) from tablename
create table #test
col1 varchar(200),
col2 varchar(10),
col3 varchar(10))
insert into #test(col1,col2,col3) values('Error transferring ExtensionIn data for enhancement &1', '3456134','49012345')
insert into #test(col1,col2,col3) values('Error transferring ExtensionIn data for enhancement &1', 'CI_EKKODB',NULL)
insert into #test(col1,col2,col3) values('Account & does not exist in chart of accounts & ', 'N/A','TIC')
insert into #test(col1,col2,col3) values('Account & does not exist in chart of accounts & ', NULL,NULL)
select isnull(Replace(ISNULL(STUFF(col1, CHARINDEX('&', col1), 1, isnull(col2, '&')),col1),'&',isnull(col3,'&')),col1) from #test
--Prashanth
Maybe you are looking for
-
HP Laserjet Pro P1102W not printing even though it's installed...
Hello everyone. I'm relatively new to Arch, especially new with configuring cups. I just bought an HP LaserJet Pro p1102w wireless printer. I set it up on my dads laptop via plugging it into the usb and it automatically ran the setup program and I se
-
HT4623 how do i restore the safari and camera icons?
how do i restore the safari and camera icons?
-
Adobe opens up fine but when I click on "Edit" it wil not open up and dissapears
-
I can't get any response when I try to buy an onli...
I can't get any response when I try to buy an online number....your response just sits and spins...please advise
-
Can someone please tell me what Weblogic 8.1 related configuration changes I need to make (Operating System related) when I am migrating from Solaris 8 to Solaris 9? Thanks in advance.