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?
thx
The escape is for the compiler, I think, and then you need to escape the backslash.
Try "\\\\".
� {�
Similar Messages
-
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... -
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 -
How to replace the '&' character with '&' in xi
Hi,
i need to replace the '&' character with ' &'.but i f i am converting it is displaying as '&' because internally '&' = '&'.
beacuse of this it is not converting.
is there any possiblity to change the standard conversion in xi.Graphical mapping does not support special character like & , <,> to be mapped.
You can encode & as and in UTF-8 only.
if you want the special character to be used, Opt XSLT mapping with ISO-8859-1 encoding
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:template match="/">
<xsl:copy-of select="*" />
</xsl:template>
</xsl:stylesheet>
How to Work with Character Encodings in Process Integration (NW7.0)
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42 -
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 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 -
How to escape the character in a string?
I have the following code that is causing an error. I'm
attempting to use < (less than) character in a string that is
part of a dynamic query:
<cfif url.age eq 1>
<cfset askAge = " < 15">
<cfelseif url.age eq 10>
<cfset askAge = " Between 56 and 60">
<cfelseif url.age eq 11>
<cfset askAge = " > 60">
</cfif>
The error occurs as a result of the line <cfset askAge = "
< 15">. The > 60 works fine. What I need is to build the
SQL statement SELECT * FROM myTable WHERE age < 15
ColdFusion sets the string properly but when I try to run the
query I guess it thinks I'm trying to open a tag. The exact error
is:
The content beginning "< " is not legal markup. Perhaps
the " " () character should be a letter.
The content beginning "< " is not legal markup. Perhaps
the " " () character should be a letter.
I can't use the ASCII code for this character as the database
will obviously crap out.
Any help would be greatly appreciated and many thanks in
advance.
DaveDave,
What if you passed off the output of the lt/gt symbols to the
query itself?
Something like,
<cfif url.age eq 1>
<cfset compareOperator = "less"/>
<cfset askAge = "15">
<cfelseif url.age eq 10>
<cfset compareOperator = "between"/>
<cfset askAge = " 56 and 60">
<cfelseif url.age eq 11>
<cfset compareOperator = "greater"/>
<cfset askAge = "60">
</cfif>
Then in the query:
<cfquery name="qTest" datasource="dsn">
SELECT * FROM myTable
WHERE age
<cfswitch expression="#compareOperator#">
<cfcase value="less">
<
</cfcase>
<cfcase value="greater">
>
</cfcase>
<cfcase value="between">
BETWEEN
</cfcase>
<cfdefaultcase>
=
</cfdefaultcase>
</cfswitch>
#askAge#
</cfquery>
Probably a better way, at least a more efficient way, but
just a thought...cfswitch processed pretty quickly and this would
remove any issues with trying to use <> symbols.
Cheers,
Craig -
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. :-) -
Having the '\' character in a string
I get errors when I try to construct a string, say like this:
String blahblah = new String("IBM\ROOT\IMAGE");
Basically it seems like I can't store that '\' character in a string at all. Is this true?
Thanks in advance.the '\' character is used to indicate an escape sequence, used for things like '\n' (new line). To do what you want you can do this:
String blahblah = new String("IBM\\ROOT\\IMAGE"); //notice the double slash '\\' you would also have to do this for double and single quotes, e.g. ( new String("Bill said, \" Anne told me to \'go home now\'\"") : for... Bill said, "Anne told me to 'go home now'") -
Replacing the letters in a string
I have an odd set of fields for properties for my client.
Some have multiple
letters which correspond to a code table. How can I loop
through the string
and replace the letters with words
For example
A = central air
B = ceiling fan
C = A/C Unit
If the field looks like 'ABC', it would be outputted to the
page as 'central
air ceiling fan A/C Unit'
Wally Kolcz
MyNextPet.org
Founder / Developer
586.871.4126You don't say how many unique letters you have, but I presume
it is 26 or less. If that's the case, you could index an array that
has been initialized with the words. See concept code below. It
assumes only upper case letters. -
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. -
Find the count of the character in a string
Hi,
i have a scenario like i have one string in that character is repeated for more than one time.
i want to know how many times that character is appeared in that string by using sql query.
example: "Hello welcome to oracle world" In this i want to know how many time "e" is appeared..
i think we can achieve by using instr and substr but i am not clear can any body please help me by using sql query to solve this issueregexp_count() function.
Better answers available on the SQL-PLSQL forum. PL/SQL
Edited by: SK1 on May 24, 2012 11:30 AM -
How to replace a character in a string
Hello Powerusers
First i'me new in the applescripting so hope you can tell me a few hint to get on.
I Have been trying to find a way to replace characters in a string using applescript. but with no luck
Anybody having a script that can give me a clue on this.
I'me normally programming in windows.... yeah i know there is a first time for everything.Okay i solved my problem but why arent the folder renamed?
property oldfolder : ""
property newfolder : ""
property SS : "."
property RS : " "
to replaceText(someText, oldItem, newItem)
replace all occurances of oldItem with newItem
parameters - someText [text]: the text containing the item(s) to change
oldItem [text, list of text]: the item to be replaced
newItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
try
set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
on error errorMessage number errorNumber -- oops
set AppleScript's text item delimiters to tempTID
error errorMessage number errorNumber -- pass it on
end try
return someText
end replaceText
tell application "Finder"
set these_items to the selection
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items) as alias
set this_info to info for this_item
set oldfolder to name of this_info
set newfolder to replaceText(oldfolder, SS, RS)
set name of this_info to newfolder
end repeat -
Counting the character in a string
How to find the number of repeated characters in a string
example- 'RAJA' In this string how many 'A' are thereA beautiful query posted by a guru in this forum long time ago.
SQL> set line 1000
SQL> l
1 SELECT ename
2 , Letter_repetition
3 , COUNT(*)repetition_count
4 FROM ( SELECT ename
5 , Letter_repetition
6 FROM emp
7 MODEL
8 RETURN UPDATED ROWS
9 PARTITION BY (ename)
10 DIMENSION BY (0 i)
11 MEASURES (ename Letter_repetition)
12 ( Letter_repetition[FOR i FROM 1 TO
13 length(Letter_repetition[0])
14 INCREMENT 1] = SUBSTR(Letter_repetition[0],CV(i),1)
15 )
16 )--End of FROM clause
17 GROUP BY ename
18 , Letter_repetition
19* HAVING COUNT(*) > 1
SQL> /
ENAME LETTER_REPETITION REPETITION_COUNT
SCOTT T 2
TURNER R 2
ALLEN L 2
MILLER L 2
ADAMS A 2
SQL>
Maybe you are looking for
-
How do you connect you macbook pro to a Sony Bravia tv with a Belkin cord!?!?!?!?!?!?!? We know how to set it up, but what setting do you put your tv on!?!?!? we have tried everything, but it wont work!!!!!!!!! HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
How many users and how often a particular discoverer report is being run?
Hi there, We run discoverer(4i) reports from portal. The question is: How to find out the number of users and how often a particular discoverer report is being run? Many Thanks in advance. Naren
-
Looking to buy this phone what i want to know are 1 Performance 2 Call logs(How much entries) 3 Can i read pdf files in this phone if yes then till how much mb it supports 4 Touch Function 5 Themes - Does it supports those .NTH old series 40 themes S
-
Copy data from Iphone to a new macbook pro.
Hi, I have a new macbook pro and would like to copy my Iphone music, apps and contacts to the new macbook. How can I do that? Thanks in advance!
-
2007 MBPro suddenly switches off and won't turn on for days..
..but then works fine again for a few weeks before it dies again. The battery is still OK and the charger has been changed recently. When it's working it's working solid, on battery as well as plugged-in. But every few weeks, all of a sudden it just