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'")
Similar Messages
-
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 "\\\\".
� {� -
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 -
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> -
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 -
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.. -
My new wireless keyboard is repeating the "\" character endlessly. It also inserts the '\" into strings of characters as I type them in word or safari or firefox. I can't erase the characters fast enough or type fast enough not to get these characters. \Help!
Try changing the batteries on the keyboard or see if the keyboard has some sort of reset available.
-
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 -
The first character in a string
I need to return the first character of a string, convert it to an integer, and compare it with another integer to see if they're the same. Sounds simple, even for me, but it won't work!!!
// First question >
Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
Variables.placeholder = (int) userValue1.charAt(0);This is the error I get
C:\Documents and Settings\imholt\My Documents\OOPAttempt\21_Questions\Engine.java:170: cannot resolve symbol
symbol : method charAt (int)
location: class java.lang.Object
Variables.placeholder = (int) userValue1.charAt(0);
^
1 error
I have a sneaky suspicion that once I find out what the problem was, I will ask myself why I didn't see it before...Try this
Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
String str = userValue1.toString();
Variables.placeholder = (int) str.charAt(0); -
Inserting the "enter" character in a String
Hi,
I would like to insert a "enter" character in a String to create a new line.
something like this
String test = "teste" + char(10) + "teste";
Thanks in advanced
RicardoAre you trying to do this in an email? You didn't mention that. If your email encoding doesn't support new lines (the most simple encoding doesn't) you can't send them. I don't know why you'd get those results though, unless you actually put "\\n\\r" in the Java program.
Anyway, it's not "my solution" it's just a fact. '\n' is the newline character and '\r' is the carriage return character. -
Hello my Friends:
I have a string that looks like this in a column:
Hello, World, Hello, Planet
I want to replace only the first occurrence so that the result looks like this:
Hello World, Hello, Planet
Working on some bad data source.
I need to replace the character regardless of it's location as long as it is the first.
I tried something like this, but I soon discovered that if the comma or character is missing the the string may get truncated or altered. If there are no characters in the string, then I want to simply leave it alone.
Here is where I am at:
DECLARE @MyValue NVARCHAR(MAX) = 'Hello, World, Hello, Planet';
SELECT MyString = STUFF('Hello, World', CHARINDEX(',', @MyValue, 0), 1, ' ');
Thanks my friends.I have a string that looks like this in a column:
Hello, World, Hello, Planet
Why doesn't it say Hello Kitty?
Oh, sorry about that. Anyway:
SELECT MyString = CASE WHEN CHARINDEX(',', @MyValue, 0) >= 1
THEN STUFF(MyString, CHARINDEX(',', @MyValue, 0), 1, ' ')
ELSE MyString
END;
Erland Sommarskog, SQL Server MVP, [email protected]
Erland, love you sense of humor!! :)
Thanks for the solution. -
How we can find the last character in a string(Urgent Plz!)
Gurus!
How we can find the last character in a string.
e.g i have a string say "Str" with value "10-01".
Now i want to find the last character in "Str" i.e "ONE=1".
i am using Oracle developer 6i with Oracle 8i(1.7).
Plz help!
Many thanks!Use the substr() and length() functions -
x := '10-01';
y := substr(x, length(x)); -
Count the occurance of a character in a string
What is the function to count the occurance of a character in a string.
like 'test test1 test2 test3' with in this string there are 3 white spaces.
instr will give the first one, replace will change the all... and what's for the occurance (number of white spaces, which is 3 in this case) count
Message was edited by:
gladnnSQL> var a varchar2(25)
SQL> exec :a := 'gghhhh999jjjj'
 
PL/SQL procedure successfully completed.
 
SQL> select length(:a) - nvl(length(replace(:a,'h','')),0) from dual;
 
LENGTH(:A)-NVL(LENGTH(REPLACE(:A,'H','')),0)
4Rgds. -
Count the occurence of a character in a string
Post Author: halfpat
CA Forum: Formula
Hello to everyone,
I use CR 8,0. Is anyone can tell me if this is possible:
I have a string "12345-C-1 23456-C-2 34567-C-4", how can I count the occurence of the "C" character in this string ?Is the InStr function can help me to do this ?
I appreciate any suggestion,
Thanks.Post Author: bettername
CA Forum: Formula
How about measuring the length of the string, and subtracting the length of the same string where C is replaced with <nothing>?
len("12345-C-1 23456-C-2 34567-C-4") - len(replace("12345-C-1 23456-C-2 34567-C-4" , "C", "")) -
Which method to count the number of character in a string?
Hi all,
I want to know which class and method to count the number of character in a string?
Garyhttp://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
Maybe you are looking for
-
Discovery using a GC Server or Specific DC
I have seen references to syntax used to perform discovery against a specific DC or a Global Catalog Server. Those references all point to SCCM 2007. Is this still possible in SCCM 2012 R2? Also, the syntax is unclear. If you want to query a specific
-
Java 2 update causing Safari crashes?
Hello. I play poker online. Ever since the last Java update, Safari crashes after around 20 mins of starting a game. I've tried using Firefox but it still crashes. I have tried a Safari reset and repaired permissions, but to no avail. I copied the de
-
Posting change from Unrestricted to Quality inspection
Hi Experts, Help please. I am trying to do posting chnage using MB1B transaction (322 Mvt type). But I'am having an error : "Change the inspection stock of material XXXX in QM only". I do not know what this error means, Please someone help me. Initia
-
Install license via C.L.I
Hi people, I need to install the license using saplicense.exe -install ifile=. I´ve logged with user sidadm and execute this command and I get the next message error: SAPLICENSE (Release 701) ERROR *** ERROR: Can not set DbSl trace function
-
Using latest Adobe reader on my mac
I downloaded the latest Adobe reader for a software program I will need on my Mac. Using Safari browser. Demo of software worked fine. But now I can't see/print my online bank and credit card statements. Why?