Assigning a Character in a String
Looking to assign a character in a string but it looks like
charAt is read only? Ideas?
+ is not a syntactic rule about source line
continuation, it is rather invoking a String
operator.
This works due to the source line continuation if C:
#include <stdio.h>
int main() {
printf("%s\n", "MMMEEEIII \
OOMMMEI");
I'm on this ice here, but isn't that done by the preprocessor, and is thus not a part of the C programming language?
You can use a preprocessor on the Java language as well if you want to.
Kaj
Similar Messages
-
Replacing a special character in a string with another string
Hi
I need to replace a special character in a string with another string.
Say there is a string - "abc's def's are alphabets"
and i need to replace all the ' (apostrophe) with &apos& ..which should look like as below
"abc&apos&s def&apos&s are alphabets" .
Kindly let me know how this requirement can be met.
Regards
SukumariREPLACE
Syntax Forms
Pattern-based replacement
1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
pattern
IN [section_of] dobj WITH new
[IN {BYTE|CHARACTER} MODE]
[{RESPECTING|IGNORING} CASE]
[REPLACEMENT COUNT rcnt]
{ {[REPLACEMENT OFFSET roff]
[REPLACEMENT LENGTH rlen]}
| [RESULTS result_tab|result_wa] }.
Position-based replacement
2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {BYTE|CHARACTER} MODE].
Effect
This statement replaces characters or bytes of the variable dobj by characters or bytes of the data object new. Here, position-based and pattern-based replacement are possible.
When the replacement is executed, an interim result without a length limit is implicitly generated and the interim result is transferred to the data object dobj. If the length of the interim result is longer than the length of dobj, the data is cut off on the right in the case of data objects of fixed length. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or hexadecimal zeroes. Data objects of variable length are adjusted. If data is cut off to the right when the interim result is assigned, sy-subrc is set to 2.
In the case of character string processing, the closing spaces are taken into account for data objects dobj of fixed length; they are not taken into account in the case of new.
System fields
sy-subrc Meaning
0 The specified section or subsequence was replaced by the content of new and the result is available in full in dobj.
2 The specified section or subsequence was replaced in dobj by the contents of new and the result of the replacement was cut off to the right.
4 The subsequence in sub_string was not found in dobj in the pattern-based search.
8 The data objects sub_string and new contain double-byte characters that cannot be interpreted.
Note
These forms of the statement REPLACE replace the following obsolete form:
REPLACE sub_string WITH
Syntax
REPLACE sub_string WITH new INTO dobj
[IN {BYTE|CHARACTER} MODE]
[LENGTH len].
Extras:
1. ... IN {BYTE|CHARACTER} MODE
2. ... LENGTH len
Effect
This statement searches through a byte string or character string dobj for the subsequence specified in sub_string and replaces the first byte or character string in dobj that matches sub_string with the contents of the data object new.
The memory areas of sub_string and new must not overlap, otherwise the result is undefined. If sub_string is an empty string, the point before the first character or byte of the search area is found and the content of new is inserted before the first character.
During character string processing, the closing blank is considered for data objects dobj, sub_string and new of type c, d, n or t.
System Fields
sy-subrc Meaning
0 The subsequence in sub_string was replaced in the target field dobj with the content of new.
4 The subsequence in sub_string could not be replaced in the target field dobj with the contents of new.
Note
This variant of the statement REPLACE will be replaced, beginning with Release 6.10, with a new variant.
Addition 1
... IN {BYTE|CHARACTER} MODE
Effect
The optional addition IN {BYTE|CHARACTER} MODE determines whether byte or character string processing will be executed. If the addition is not specified, character string processing is executed. Depending on the processing type, the data objects sub_string, new, and dobj must be byte or character type.
Addition 2
... LENGTH len
Effect
If the addition LENGTH is not specified, all the data objects involved are evaluated in their entire length. If the addition LENGTH is specified, only the first len bytes or characters of sub_string are used for the search. For len, a data object of the type i is expected.
If the length of the interim result is longer than the length of dobj, data objects of fixed length will be cut off to the right. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or with hexadecimal 0. Data objects of variable length are adapted.
Example
After the replacements, text1 contains the complete content "I should know that you know", while text2 has the cut-off content "I should know that".
DATA: text1 TYPE string VALUE 'I know you know',
text2(18) TYPE c LENGTH 18 VALUE 'I know you know',
sub_string TYPE string VALUE 'know',
new TYPE string VALUE 'should know that'.
REPLACE sub_string WITH new INTO text1.
REPLACE sub_string WITH new INTO text2. -
How to count number of occurences of a character in a string
I want to get the count of occurences of a character within a string. Is there any function for this or should i go for a PLSQL.
For example is the sting is "occurences" & if i search for character "c", the answer should be 3.
Regards,
Sunil.SQL> select length('occurence') - length(replace('occurence','c')) from dual;
LENGTH('OCCURENCE')-LENGTH(REPLACE('OCCURENCE','C'))
3 -
How to get each character in a string
as in 'C' we use arrays to get each character of a string stored in array.how can we get each character of a string stored in a variable.
Hi,
For that you need to do offset.
for example one variable called VAR contains string 'HUMERAH'.
if you want each character of that string then you need to decalre as many variable as the number of string.
like
data : var1(1),
var2(1),
var(3),
var(4).
var1 = var+(1).
var2 = var+1(1).
var3 = var+2(1).
var4 = var+3(1).
now var1,var2,var3,var4. contains the single characters.
Regards,
Guru
mark helpful answers -
Hi Friends,
How to assign a value to a string. Coz I need to compare the strings with the user entered string and process the logic.
Example : p_pass TYPE string p_pass = 'APPLE'.
Regards,
SMPHi,
Try like this.
parameters : p_pass TYPE string value 'APPLE'.
at selection-screen on p_pass.
If p_pass co 'APPLE'.
statement
endif.
Regards,
Prashant -
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.. -
Function in oracle to find number of occurances of a character in a string
hi,
is there any function in oracle to find the number of ocurrances of a character in a string ?
or is there any simple way of doing the same, rather than writting many lines of code as my program is already very complex.
MariaHi Maria,
I don't know of such a function in Oracle, but maybe you could use this:
length(search_string) - length(replace(search_string, character_to_be_found))
For example: select length('Hello') - length ( replace('Hello', 'l')) from dual;
Hope this is what you're looking for
Danny -
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 -
How to get a set of character within a string?
Hi,
I need to cut a set of character within a string. I have tried everthing but I need help.
Example.
Database Version 11.2.0.3
create table tst_string (message varchar2(600));
insert into tst_string values ('ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)');
insert into tst_string values ('ANE4175I Starting Full VM restore of VMware Virtual Machine ''mfujiwara'' target node name=''VC1_DC1'', data mover node name=''VC1_DC1_DM3'' (SESSION: 3780)');
commit;
select * from tst_string;
MESSAGE
ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)
ANE4175I Starting Full VM restore of VMware Virtual Machine 'mfujiwara' target node name='VC1_DC1', data mover node name='VC1_DC1_DM3' (SESSION: 3780)
## I want get
# From first line following values:
node OSOGBO
filespace OSOGBO\SystemState
examined 43
deleted 43
retrying 0
failed 0
# From second line
mfujiwara
VC1_DC1
VC1_DC1_DM3Any help can be useful...
Thanks in advance.Hi Frank,
It looks like message can be seen as delimited lsit of sub-messages, where a number of different characters (perhaps ',' amd ':') may serve as delimiters. Each sub-message may or consist (entirely or in part) of something you want to display.Yes. In my first case where is "ANR0166I" I want get the characteres before "," (e.g "OSOGBO," I want get "OSOGBO") excluding "(SESSION: 1506, PROCESS: 2)"
Would a user-define PL/SQL function be okay for you?Yes.. no problem.
I'm not good with shell script, but will try show what I want using SHELL commands:
See this example:
### I create a file named "tst_string"
$ vi tst_string
ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState\NULL\System State\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)
## So I used a function sed to get my desired values. The command bellow is poor, but My point is the result.
$ cat tst_string | sed 's/ANR0166I.*node //g' | sed 's/, filespace//g' | sed 's/, copygroup BACKUP and object type GROUP BASE with processing statistics: //g' | sed 's/. (SESSION.*//g' | sed 's/, deleted//g' | sed 's/, retrying//g' | sed 's/, and failed//g'
OSOGBO OSOGBO\SystemState\NULL\System State\SystemState 43 43 0 0The result was:
NODE FILESPACE Examined Deleted Retrying Failed
OSOGBO OSOGBO\SystemState\NULL\System State\SystemState 43 43 0 0I will go check the links wich you mentioned.
Thanks -
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... -
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); -
How will you locate a specific character inside a string?
Thanks in advance!!!> The best place to start with this type of question is
the documentation. Take a look at string functions:
>
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_18.html
Absolutely.
Even if one types in "coldfusion find in string" in Google,
the first
result is on the money (for CFMX7, not CF8, but still).
Adam -
Truncating last character in a string
I am making a dialpad. It is just for display so I am using a
string for the numbers selected. I am trying to make a back button
that would clear the last number added. I tried mystring.length-1
but that doesn't seem to be doing the trick. Is there a simple way
to truncate the last character in a string, of variable
length??Here's an example
var someStr="asdfasdf saf asdf sadfas dfs fsa asf";
while (someStr.length) {
someStr = someStr.substring(0,someStr.length-1)
trace(someStr);
} -
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'")
Maybe you are looking for
-
Erasing Time Machine hard drive after formatting for both PPC and Intel
Ok, I made a mistake. First I formatted a Western Digital 500 gig hard drive for both my wife's PPC G4 laptop and my own Intel MBP laptop, so we could both use Leopard's Time Machine for backing up to the same drive. That wasn't my mistake though, it
-
What has happened to safari? Macbook pro 10.10. After installing antivirus, I can only get and use firefox.
-
Windows 7 Partition Unusable After OS X Yosemite Upgrade
Hello All, I have an Early 2013 15" MBPR, and I just recently upgraded to OS X 10.10. (I made a time machine backup right before). However, it seems that my Windows 7 partition is not bootable anymore using "alt" on boot, and it also isn't showing up
-
For those who helped me on my last issue, thank you. I wrote this program from the code I last executed. What I want this program to do is take A, B, C and shuffle them badly. Thus I use int random = (int)(Math.random()* (range.length)); instead
-
Folder of application builder(*.exe) with run-time DLL
My application consists of main.vi, subvi folder, and example folder. In addition, I have to add the run-time libraries for add-on tool kit (advanced signal processing, lvwa.dll) which should be located in the root folder. (For exe application, can I