Replace a character from a string
Hi,
how can I replace a particular character from a string on a particular occurrence? Say for eg, if i wan to replace 'a' of second occurrence from 'abcabcabc', then what should i do? I guess the normal REPLACE function replaces every occurrence in a given string. So is there any other way to solve this?
Thanks!
If you are in 9i:
Then you got to split the string into based on the nth position.
SQL> select replace('abddefabc','a','x') from dual;
REPLACE('
xbddefxbc
SQL> select instr('abddefabc','a',2) from dual;
INSTR('ABDDEFABC','A',2)
7
SQL> select substr('abddefabc',1,instr('abddefabc','a',2)-1),substr('abddefabc',instr('abddefabc','a',2)) from dual;
SUBSTR SUB
abddef abc
SQL> select substr('abddefabc',1,instr('abddefabc','a',2)-1),replace(substr('abddefabc',instr('abddefabc','a',2)),'a','X') as replaced from dual;
SUBSTR REP
abddef XbcOfcourse, later on you can join the string..
Jithendra
Similar Messages
-
Replace tab character from string in ABAP
hi experts,
I have a string like this "a<tab character>b<tab character>c<tab character>d". for my processing i want the output like "abcd". How can i replace all occurances of this tab character from my string.
tab character = a hexa decimal character. I dont know the hex value for this.
regards
Raghavhi you joined SCN in 2007 its a way long time to say.. ur new.. any ways.
after declaring the lv_tab as I said...
REPLACE ALL OCCURRENCES OF lv_tab in <string> with space. -
Replacing a character in a string to another character
hi,
i need to write a function or procedure to replace the character of a string value suppose:
l_error:= 'abcdefghijklmnop' is a string
i need write a function or procedure to replace the character "c" to "z"
that data in l_error is not in any table.
thanks,
AJI want to Replace all the Existence of the word - "Test" in a string with "Test1" whereever a space exits before the word Test and someother alphabet after "Test" i.e. Test will be replaced with Test1 if a word starts with Test and contains more alphabets also. For example - TestName should be replaced with Test1Name while MyTest should not be updated to MyTest1.
I have tried to use below query which uses oracle regular expressions -
SELECT REGEXP_REPLACE('MYCOMPANY TEST TESTGEET INDIA PVT LTD TEST','\s(TEST)\w',' TEST1') FROM DUAL
Output -
"MYCOMPANY TEST *TEST1EET* INDIA PVT LTD TEST"
Here, it has also replaced the G also from TESTGEET and resulted in TEST1EET while i want TEST1GEET.
Can someone please suggest how can i do this..... may b m doing some silly mistake but sorry m a newbie to regular expression...
Thanks in advance.. -
How to replace a character in a string with blank space.
Hi,
How to replace a character in a string with blank space.
Note:
I have to change string CL_DS_1===========CM01 to CL_DS_1 CM01.
i.e) I have to replace '=' with ' '.
I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
Its not working.Hi,
Try with this..
call method textedit- >replace_all
exporting
case_sensitive_mode = case_sensitive_mode
replace_string = replace_string
search_string = search_string
whole_word_mode = whole_word_mode
changing
counter = counter
exceptions
error_cntl_call_method = 1
invalid_parameter = 2.
<b>Parameters</b> <b> Description</b> <b> Possible values</b>
case_sensitive_mode Upper-/lowercase false Do not observe (default value)
true Observe
replace_string Text to replace the
occurrences of
SEARCH_STRING
search_string Text to be replaced
whole_word_mode Only replace whole words false Find whole words and
parts of words (default
value)
true Only find whole words
counter Return value specifying how
many times the search string
was replaced
Regards,
Jayaram... -
Strip the first character from a string
i am trying to strip the leftmost character from a string
using the following:
<cfset Charges.DTL_CHG_AMT_EDIT =
#Right(Charges.DTL_CHG_AMT_EDIT,Len(Charges.DTL_CHG_AMT_EDIT)-1)#>
i keep getting the following error:
Parameter 2 of function Right which is now -1 must be a
positive integer> RemoveChars() much easier than Right()? How so?
Semantically, if the object of the exercise is to *REMOVE
CHARacters from a
string* (which it is, in this case), it is simply better
coding to use
removeChars() rather than right(). That, and it's one less
function call
(the RIGHT() solution also requires a call to LEN() for it to
work).
So removeChars() is "easier" because it reflects the intent
of the exercise
directly, is simpler logic, is easier to read, and - I can't
be arsed
counting keystrokes - is probably less typing.
That'd be how.
Adam -
Replace a character in a String array
I have an array of strings and am trying to replace the ' character with a space. I keep getting either a cannot be applied or cannot resolve symbol error. Can anyone help?
String arrayList = request.getParameter("field");
String newList = arrayList.replace("\'", " ");the replace method of the String class takes two parameters and both of them are characters not strings use it like this
arrayList.replace('\'', ' ');that should fix it -
Replacing the \ character in a string
I'm having trouble replacing a backslash in a string. I use .indexOf() to find the character, but I have to use an escape character and write .index("\\"), but it doesn't work - it returns -1.
Also, replace() doesn't work - gives me an java.util.regex.PatternSyntaxException. Any ideas?
thxThe escape is for the compiler, I think, and then you need to escape the backslash.
Try "\\\\".
� {� -
Replacing a character in a String
Hi All,
How can I replace a character ' which appears in a String into \'There is a method in String that replaces all
occurrences of one character with anothercharacter.
It's called, hold your breath now, "replace".But tho OP wants to replace one character with two
characters :)You're right, I missed that. Well, serves me right for being sarcastic. :-) -
Replace a character in a string
Hi,
I've been tearing my hair out trying to do something very simple, replace a backslash character in a string with an underscore. I've searched online and discovered the -replace parameter which you would think would work fine but no, it seems to get in a
tizzy because the character I want to replace is a backslash and I get an error: "Invalid regualr expression pattern".
Here's what I have which produces the error:
$str = 'start\end'
$str = $str -replace '\','_'
Can someone tell me how to do this? I simply want to replace a backslash with an underscore.
thanks
Jamie
http://sqlblog.com/blogs/jamie_thomson/ |
@jamiet |
About mesod's law. I spend half an hour trying to figure this out and then as soon as I post this thread I figure it. The following works:
$str = 'start\end'
$str = $str -replace '\\','_'
$str
http://sqlblog.com/blogs/jamie_thomson/ |
@jamiet |
About me
"-replace" requires a regular expression for each argument, which is why you needed to escape your backslash with another backslash. If you use the replace() string method, you are not required to use regular expressions:
$str = $str.replace('\','_') will work exactly as you expect it to. -
Replace a character in the string using JavaScript
Hello,
I would like to ask for help. I have a field in the xml file, which contains a string, that is bound to a text box on the form.
What would be the syntax to replace a special character in the string with the carriage return?
Thank you.Huh?
I didn't post my script...
It sure is no clean programming since I just took Steve's solutions and delted the ligns I didn't want (the app allert)
Though in the end I've taken the boolean out, or better replaced it with the replacement function, it repeats the replacement no matter how much "ü"'s are in there. (I needed the boolean though, since as long as it was true, the if should be executed.)
Somehow it worked... not 100% sure why, but it worked.
if (findChar(this.rawValue)) {
function findChar(str)
{ for (var i=0; i < str.length; i++)
if (str.charAt(i) == "ü")
this.rawValue = this.rawValue.replace(/ü/,"ue") -
Counting a Special Character from a String
Hello,
I have a String let say 'ABC-X', 'ABC-X-Y' ....
so how can we find the count/No. of Hypen('-') .. in a string....I have a String let say 'ABC-X', 'ABC-X-Y' ....
so how can we find the count/No. of Hypen('-') .. in a string....
SQL> var str varchar2(20);
SQL> exec :str := 'ABC-X-Y';
PL/SQL procedure successfully completed.
SQL> select length(:str) - nvl(length(replace(:str,'-')),0) from dual;
LENGTH(:STR)-NVL(LENGTH(REPLACE(:STR,'-')),0)
2
SQL> -
Replace read character from file
HI,
I have updated my labview 2014 and have a load and save function wich not working on the new version.
It says that the read character from file is not supported any more.
How to i fix it to run in labview 2014?
Attachments:
Load.png 62 KB
Save.png 365 KBBob_Schor wrote:
Please do not attach tiny pictures of your VIs (I can't see them clearly). Instead, attach the VIs, themselves -- this lets us open them in LabVIEW, see if there are any broken arrows, read the error messages, and actually try your code (any test any fix we might suggest). Help us to help you.
Do you know about Snippets? This is what looks like a .PNG file, but can be dropped in a LabVIEW Block Diagram to become executable code. Find it on the Edit menu of the Block Diagram.
Bob Schor
HI,
OK, I have now attach my VIs.
//Ronny
Attachments:
Save.vi 11 KB
Load.vi 11 KB -
Picking character from a string
Hi guys
How to pick each character of a string containing few character without using a loop. Like "LabVIEW" will become a array of string "L","a","b" etc
Thanks in advance
NiladriWhy would you not want to use a loop?
You could use String Subset in a loop to get each byte.
You could alsoe use String to U8 array to get an array of bytes. Then convert that back to individual string characters by using the typecast function in a loop with autoindexing turned on.
Attachments:
Example_VI_BD.png 10 KB -
How to get specific character from a string
I have a value such as: 0-5 or 123-30. This is a combination
from 2 different IDs.
All I need is to get the number on the right (5 from 0-5 OR
30 from 123), any number on the right of the "-" character not
including
the "-"
I'm not sure what ColdFusion function can I use safely.
I said safely since all I can find is either Left or Right
functions. With these 2 functions, I need to specify the number of
character to extract while in my case the application is growing so
the ID may currently be only 1 digit each (0-5) but later it may
grow longer (123-5677).
If anyone know the function, please help me. Thank you!Something like this?
Mid(string, Find("-",string)+1 ,
Len(string)-Find("-",string))
Since
Mid(string, start, count)
and
Len(string or binary object)
and
Find(substring, string [, start ])
Or perhaps ....
ListLast(string, "-")
since
ListLast(list [, delimiters ])
Phil -
Replace hex character in a string with another hex character
Hi Guys,
Heres a problem scenario, hex character 92 looks very much like hex character 27 (apostrophe).
I need to write a program that can replace all hex character 92 to hex 27 in a string.
Being a novice on the regular expressions, I would appreciate if somebody can show
the exact syntax to to perform this replacement.
Many Thanks
-AnilI don't think you need to use regex to do this:
String s = something();
char a = 0x27;
char b = 0x92;
s.replace(a,b);
And don't forget that since Strings are immutable you need:
s = s.replace(a,b);to do anything useful.
Maybe you are looking for
-
Intra pnat to plant transfer -STO- Freight is going to add on materialFG
Dear Friends , I wants to transfer stock from plant -1 to plant-2 (Intra company means in one company code plant to plant) I am doing 1)STO-PO 2)MIGO_GI (Mov.type-351) 3)MIGO (Mov.type-101) using standard pricing of STO at header level. But when i pu
-
Hi, I have imported some photos, and edited them using Aperture. But I do not know how to "export" the edited photos. Like I "move the photo dsc001 behind dsc0008", but it still does not make any change after I export them. Thanks. Ed
-
Changed to a foreign store, and can't get back.
Hello, I tried to DL an album from my ipad and it was only available on the Belgium store. So, I switched, couldn't DL it, and now I want back to the US store, but I am helpless. Any ideas on how to switch back on the ipad?
-
Cannot start Domain Controller and node
I installed Oracle db v9.2.0.1, oracle 9ias j2ee and web cache Release 2 (v9.0.3) and CMSDK v9.0.3 for windows on single machine. Installation was fine. However, when I try to start ifs domain controller, I got following error in ifsctl.log file. +++
-
Receiving this error when trying to download firefox.
The error reads System.ComponentModel.Win32Exception: The system can not find file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfostartInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(Pr