Function to replace nth occurrence of a character
Hi,
Is there a function already to replace the nth occurrence of a character ?
For example: 'ORACLE IS THE INFORMATION COMPANY'
Replace 3rd 'O' from left with 0 (Zero):
'ORACLE IS THE INFORMATI0N COMPANY'
Thanks !
Regrads,
Pat
SQL> var a varchar2(100);
SQL> var occ number;
SQL> exec :a := 'ORACLE IS THE INFORMATION COMPANY';
PL/SQL procedure successfully completed.
SQL> exec :occ := 3;
PL/SQL procedure successfully completed.
SQL> select SUBSTR(:A,1, instr(:A,'O',1,:occ)-1)||'0'||SUBSTR(:A,instr(:A,'O',1,:occ)+1) from dual
2 /
SUBSTR(:A,1,INSTR(:A,'O',1,:OCC)-1)||'0'||SUBSTR(:A,INSTR(:A,'O',1,:OCC)+1)
ORACLE IS THE INFORMATI0N COMPANYKarthick.
Similar Messages
-
Replacing all occurrences of characters in a string with one new character?
Hi there,
I'm looking for a way that I could replace all occurrences of a set of specific characters with just one new character for each occurrence.
For example if I have a string which is "word1...word2.......word3....word4............word5" how would I be able to replace this with just one character such as ":" for each set of "." so that it would essentially appear like this "word1:word2:word3:word4:word5"
If I just use replace(".", ":") I am left with "word1:::word2:::::::word4::::word5::::::::::::"
So therefore I'm guessing this would require the use of replaceAll() maybe? but I'm not really very familiar with how regular expressions work and how this would be accomplished using them.
Any help would be greatly appreciated :) Thanks.Yes, but "." means any character, so ".\+" means "any character repeated more than once". If you just mean a full stop ("period" for you Americans :p) you should use "\.+" as your regular expression, but remember that for Java you need a '\' escape to recognise '\' as '\', so in code you'd actually type your regex as:
"\\.+"Here's an example of one way to do it:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String string = "example1.......example2...example3.....example4";
Pattern pattern = Pattern.compile("\\.+");
Matcher stringMatcher = pattern.matcher(string);
string = stringMatcher.replaceAll(":");
System.out.println(string);
}Edited by: JohnGraham on Oct 24, 2008 5:19 AM
Edited by: JohnGraham on Oct 24, 2008 5:22 AM -
How to check the occurrence of a character in a string
Hello Experts,
I have a scenario where in I have to check the occurrence of a character in a string and based on that I have to pass a data into target field.
I was wondering whether this can achieved with mapping functions or Do I have to use an UDF.
Thanks in advance.
Regards
Advit RameshHi Advit,
You can achieve this by using standard function indexOf from the text category. Pass in the input string and the character value you want to check for as the input.
Standard Functions (SAP Library - SAP Exchange Infrastructure)
If the output is -1, then the character is not in the string, otherwise it is.
Rgds
Eng Swee -
Hi, Occurrences Of Every Character In A String
Hi All,
I want to write a program wherein I can check the occurrences of every character in the string given.
What should I do, is there a in built function to do this.
Please helpI wrote this program and this works fine... Thanks
public class Main_Character_Occurence
public static void main(String args[])
String inputString = " Test String";
String matches = "abcdefghijklmnopqrstuvwxyz";
int sum = 0;
for (int i = 0; i < matches.length(); i++)
for (int ctr = 0; ctr < inputString.length(); ctr++)
if (matches.charAt(i) == Character.toLowerCase(inputString
.charAt(ctr)))
sum++;
System.out.println(matches.charAt(i) + "=" + sum);
sum = 0;
}The output I am getting is this
a=0
b=0
c=0
d=0
e=1
f=0
g=1
h=0
i=1
j=0
k=0
l=0
m=0
n=1
o=0
p=0
q=0
r=1
s=2
t=3
u=0
v=0
w=0
x=0
y=0
z=0 -
Find the nth occurrence of a string in a string
Hi,
I'm wondering if there is a method like indexOf, but finds the nth occurrence of a string
public static int occurrence(java.lang.String str,
java.lang.String toFind,
int occurrence)Cheers
Jonnyphdk wrote:
calypso was refering to promes pseudo code.What is promes? I don't understand the word. Sorry!
I put the global variable 'count' now in the method occurence
public static int occurence(String str, String toFind, int occurence){
int origLength = str.length();
int count = 0;
while(str.length()>0){
str = contains(str, toFind, count);
if(count == occurence){
int length = str.length();;
int actualPos = origLength-(length+1);
return actualPos;
count++;
return -1;
public static String contains(String str, String toFind, int count){
int occurence = str.indexOf(toFind);
if(occurence != -1 ){
count = count+1;
return str.substring(occurence+1,str.length());
}else{
return "";
}The output is 1 position to high.
I still don't get which part of the code to replace with this pseudo code: s'.indexOf('toFind', 'index'+1)
Sorry for being dimwitted!
Thanks
jonny -
DUMP: replace all occurrences of space in string1 with string2.
Why does this statement results in a dump:
replace all occurrences of space in string1 with string2.
same with
replace all occurrences of ' ' in string1 with string2.
string2 is a string without spaces!
Is there any drawback on using this statements as a workaround?
while sy-subrc eq 0.
replace space with string2 into string1.
endwhile.
Thanks
norbertHi,
See this example i got from ABAPDOCU
replacing values
DATA: t4(10) TYPE c VALUE 'abcdefghij',
string4 LIKE t4,
str41(4) TYPE c VALUE 'cdef',
str42(4) TYPE c VALUE 'klmn',
str43(2) TYPE c VALUE 'kl',
str44(6) TYPE c VALUE 'klmnop',
len4 TYPE i VALUE 2.
string4 = t4.
WRITE string4.
REPLACE str41 WITH str42 INTO string4.
WRITE / string4.
string4 = t4.
REPLACE str41 WITH str42 INTO string4 LENGTH len4.
WRITE / string4.
string4 = t4.
REPLACE str41 WITH str43 INTO string4.
WRITE / string4.
string4 = t4.
REPLACE str41 WITH str44 INTO string4.
WRITE / string4.
SKIP.
ULINE.
Example for condensing strings
DATA: string9(25) TYPE c VALUE ' one two three four',
len9 TYPE i.
len9 = strlen( string9 ).
WRITE: string9, '!'.
WRITE: / 'Length: ', len9.
CONDENSE string9.
len9 = strlen( string9 ).
WRITE: string9, '!'.
WRITE: / 'Length: ', len9.
CONDENSE string9 NO-GAPS.
len9 = strlen( string9 ).
WRITE: string9, '!'.
WRITE: / 'Length: ', len9.
SKIP.
ULINE.
Thanks & Regards,
Judith. -
Replace all occurrences of ENTER in a string
Hi,
I have a string which contains line breaks:
'<HTML><HEAD>
</HEAD>
<BODY>'
and it is shown to me in the debugger as:
'<HTML><HEAD>#</HEAD>#<BODY>'
Now I want to replace all line breaks in the string,
but
replace all occurrences of `#` in text with ' '.
doesn't work.
So if you have an idea how to replace the # symbol for Enter in a string please tell me ;).
regards,
StefanHi,
Pls use
replace all occurences of '#' in text with cl_abap_char_utilities=>newline.
Eddy -
Obselete function module replacement in ECC 6.0
Hi SDN,
Pls let me know the replacement for FM GRAPH_SET_CUA_STATUS. in ECC 6.0.
Regards,
Rahul WaghHi Rahul,
in [this blog |/people/andrea.olivieri/blog/2010/04/30/community-call-obsolete-function-modules-replacement-matrix-for-ecc-60]published several months ago, I collected my thoughts on this persistent issue.
In my opinion you can continue to use the FM GRAPH_SET_CUA_STATUS without any problems, confirming that the presence of numerous standard programs that use this method.
Regards,
Andrea -
Replace any occurence of a character in a varchar2 column
What would be the best way to replace any occurence of a character in a column (varchar2) of a table?
Lets say we want to replace any occurence of the character ~ by the character & in the column c1 of the table t.
Is it possible in pure SQL?
I did it in PL/SQL in a while loop but I am pretty sure there is a way to do that in a single SQL statement. Am I right on wrong?
Thanks
Best regards,
CarlThe Ampersand has a special meaning in SQL to mark a variable.
That's why you need to set 'scan off' or 'define off' or
For more information see here
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm#1012408
set scan off
update t
set c1=replace(c1, '~', '&'); -
Lua function to replace metatags in a string?
(Maybe this is a recipe request for the new cookbook site.)
I'd like a function that, given a string and a LrPhoto, will search and replace tags in the string with metadata from the photo. So, given a string 'The title of this photo is {{title}}', it would return a string where {{title}} has been replaced with the LrPhoto.getRawMetadata('title') (or maybe getFormattedMetadata). I'm sure it's been written more than once. Is there one out there to be shared before I write my own?
dbI spent the time on this myself and don't know why I bothered asking, it was so simple. Here's what I did. First, a general-purpose function to replace any token in a string with values from a table:
-- replace any string of characters in a string that are surrounded by curly
-- braces (e.g. {foo}) with the value in the table corresponding to 'foo'.
-- will replace all tokens in braces if there are more than one
function DFB.replaceTokens( tokenTable, str )
return str:gsub( '{(.-)}', function( token ) return tokenTable[token] end )
end
Then, if you want to do this with a photo's metadata, just pass the table that's returned from getRaw/FormattedMetadata:
line = DFB.replaceTokens( photo:getFormattedMetadata( nil ) , line )
So if line starts out with "my caption is {caption}" and the photo's caption is 'My Photo Caption', the result is "my caption is My Photo Caption".
I use this in a simple templating system that reads an HTML template from a file and does this for each line as it reads/writes it. Works well. -
Replace all occurrence with range - issue
Hi,
I have a range with "letters" like ":" or "-" or "."
Note: all entries are with option = "equal"
Now i need to "replace all occurrences" of "all entries in that range" with space.
idea:
loop at range assigning <range>.
replace all occurrences of <range>-low in aaa with space
endloop.
Any better ideas ?
Regards,
GordonSorry but i think my question was not clear.
is there another way instead of using the "loop" ?
The translate or replace statement is not the problem
thx,
Gordon -
Global User Functions not replaced in Check Contraint
Hi all,
we just moved from ODI 11.1.7 to ODI 12.1.2 an have the following problem. Our global user functions which are used in several Check Conditions are no longer replaced during code generation.
They worked like a charm in ODI 11.1.7. Any ideas?
Kind regards,
JensWe are running Scenarios and Mappings from Designer using Local and Remote Agents (Simulation and Execution Mode). No difference at all.
Global User Functions are replaced in Filters and Target Expressions but not in ODI Constraints. -
Scanning $subject for multiple occurrences of a character
Hi,
I just wanted to know if it is possible to use the GUI to check for a character threshold greater than one in the subject header.
We are seeing subjects like: this_is_a_hundred_percent_spam_header
and would want to block this kind of messages.
Any idea?
thank you,
SergioCCan you clarify on what you mean by "character threshold greater than one in the subject header" ?
when you say mulitple occurrence of a character, do you mean a repeat like "testssss" where the "s" is repeating?
What is it about this subject, " this_is_a_hundred_percent_spam_header
" that you're trying to match?
Hi,
I just wanted to know if it is possible to use the GUI to check for a character threshold greater than one in the subject header.
We are seeing subjects like: this_is_a_hundred_percent_spam_header
and would want to block this kind of messages.
Any idea?
thank you,
SergioC -
Replace last occurrence of a word in string
Hi,
I need to replace a last occurrence of a word in string. Form example:
'I like fruits and also like vegetables' need to replace last occurrence of "like" which is just before vegetables and not the "like" before the fruits.One of the solution to use the last occurrence dynamically
applicable to prior version of 11g
SELECT REGEXP_REPLACE (str, 'like', 'hate', INSTR (str, 'like', -1))
FROM (SELECT 'I like fruits and also like vegetables also like mango' str FROM DUAL)
applicable to 11g
SELECT REGEXP_REPLACE (str, 'like', 'hate', 1, REGEXP_COUNT (str, 'like'), 'i') data_col
FROM (SELECT 'I like fruits and also like vegetables also like mango' str FROM DUAL) -
How to use replace function to replace word
I am trying to write a replace function in which I replace CA with California in an address string.
I am trying to avoid using regular expression and just use other functions like replace, instr, trim etc.
But what my main confusion is how do i take care of three cases in which.
CA can be present with spaces before and after it like.
- Redwood City, CA 96403
CA can be present with spaces only before it and after it the string ends.
- Redwood City, CA
and I do not want to replace any other CA in the string that is part of other word
- Blaca Street CA
( for example do not replace ca in Blaca)
or
- Cardinal Dr CA
ThanksHi,
user6287828 wrote:
... (only four of these abbreviations need to be replaced)In that case, nesting the functions one inside another won't be too bad. But watch out: this is exactly the kind of requirement that changes over time. You might only need 4 states now, nut next year they might expand the application so that you need all 50 states (plus Puerto Rico, and DC, and ....). In that case, something like MODEL, or a user-defined PL/SQL function, would be better.
As these are abbreviations these will always be stand alone words and never part of words. And these abbreviation can be at the beginning or end or in between the string.
And any abbreviation can be present in one column.
More than one abbreviation can be present in one column
None of the abbreviations can be present in this column.
For example
column
3251 BLACA ROAD CA 94305
74 CALDWIN STREET CA
67 DIGITAL DRIVE NM
NM UNIVERSITY AVENUE 890
7645 ROCHESTER NY PARK STREET
834 GRAND AVENUE ATLANTAPost CREATE TABLE and INSERT statements for the sample data.
Include all special cases, e.g. more that one abbreviation in the same column.
Maybe you are looking for
-
Issue, cd/dvd drive not ready in time
Hello, I am new to the Apple and OS X. So far I am impressed. One issue is bothering me however. It takes some time for the cd/dvd drive to go from sleep mode to active mode. This may take up to 10 seconds. Some programs will return a message that th
-
Hooking up analog 5.1 speakers to dvd through ext
is it possible to achieve surround sound dvd playback by connecting my dvd player to the extigy's digital connection and the speakers to the analog connection? or is there any other configuration that would allow me to use the speakers with my dvd pl
-
SQL*Loader importing problem, with file with eastern european files
Hello, on Oracle 11g with UTF-8 encoding, I tried to import a csv file into a table via sqlload, the separator is the semicolon ";" all work fine except for some lines witch are not well integrated (the concerned files come from Eastern European coun
-
Hi guys, this is just an idea I have for a website, i haven't done the animations yet, but my thought is something like this: i will have an animation done in 3DsMax and imported into the timeline of my SFA, say maybe 160 frames. The animation would
-
Configure Local Machine is grayed out in Server Monitor
I'm trying to configure one of our Intel Xserves for use with Lithium for monitoring via the LOM port. When I go to Server Monitor the Configure Local Machine menu item is grayed out. All the units have the same hardware config and are working so I'm