Containers...replacing two chars with a string
public static char[] translate(String string)
Scanner sc=new Scanner(string);
int x=0;
char output[]=string.toCharArray();
for(int i=0; i<output.length; i++)
if (output=='[')
if(output[i++]=='C')
output[].remove(i);
output[].remove(i++);
output[].insert(output, i, 6);
output[].fill(output, i, i+6, "char[]");
return output;
i apologize. i am unable to edit the code.
i want to find and replace two contiguous chars, '[' and 'C' with the string "char[]" ...I have just found that remove, insert and fill do not exist in the char array...How can I edit this function to return a string after it's been edited?
the code i posted returns compile errors: Firstclass.java:163: class expected
output[].remove(i);
^
Firstclass.java:163: not a statement
output[].remove(i);
^
Firstclass.java:164: class expected
output[].remove(i++);
^
Firstclass.java:164: not a statement
output[].remove(i++);
^
Firstclass.java:165: class expected
output[].insert(output, i, 6);
^
Firstclass.java:165: not a statement
output[].insert(output, i, 6);
^
Firstclass.java:166: class expected
output[].fill(output, i, i+6, "char[]");
^
Firstclass.java:166: not a statement
output[].fill(output, i, i+6, "char[]");
^
8 errors
Similar Messages
-
How to replace one char with two chars in email address policy?
I very much like to replace the 'ß' char in the surname with 'sz'. However, applying filter '%rßsz%[email protected]' on 'Preußig' leaves me with '[email protected]'.
So, how do I replace one char with two chars in email address policy?As far as I know, your only solution is to manually create such addresses instead of using e-mail address policy.
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems." -
Replacing a char with string in a string buffer.
Hi all,
I have a huge xml file. Need to search for the following characters: ^ & | \ and replace each character with \T\ \F\ \B\ \C\ respectively.
i.e. ^ must be replaced with \T\
& must be replaced with \F\
I see that it can be done in case of String using replaceAll() but have no clue about achieving using the stringbuffer??
Any help is higly appeciated.
Thanks in advance.Hi all,
I have a huge xml file. Need to search for the
following characters: ^ & | \ and replace each
character with \T\ \F\ \B\ \C\ respectively.
i.e. ^ must be replaced with \T\
& must be replaced with \F\
I see that it can be done in case of String using
replaceAll() but have no clue about achieving using
the stringbuffer??
Any help is higly appeciated.
Thanks in advance.here the solution for your problem:
example code as follows,
StringBuffer stringBuffer = new StringBuffer("your xml content");
String xmlString = stringBuffer.toString();
char[] xmlCharArray = new char[];
xmlString.getChars(0, xmlString.length()-1, xmlCharArray, 0);
StringBuffer alteredXmlBuf = new StringBuffer();
for(int i=0; i<xmlCharArray.length; i++){
if( xmlCharArray[i] == '^'){
alteredXmlBuf.append(" \\T\\") ;
}else if(xmlCharArray[i] == '&'){
alteredXmlBuf.append(" \\F\\") ;
}else if(xmlCharArray[i] == '|'){
alteredXmlBuf.append(" \\B\\") ;
}else if(xmlCharArray[i] == '\'){
alteredXmlBuf.append(" \\C\\") ;
}else {
alteredXmlBuf.append(xmlCharArray);
now alteredXmlBuf StringBuffer object contains your solution. -
Replace one char with the other
I am reading a path,when i use the system path with the \ slash in java its not compatible in windows,
is there any facility in java for replacing the rightslash with the forward slash
i.e when we encounter '/' i wanna to replace it with '\'
sample code needed
please help me
thank in advance,
with regardsThe java file handling code will work with paths containing forward slashes, even on windows. If you want to convert to backslashes before displaying to the user or calling native code, then something like the following should work:
String myPath = "C:/Windows";
myPath = myPath.replace('/', '\\'); -
Replacing a part of a String with a new String
Hi everybody,
is there a option or a method to replace a part of a String with a String???
I only found the method "replace", but with this method I only can replace a char of the String. I don't need to replace only a char of a String, I have to replace a part of a String.
e.g.:
String str = "Hello you nice world!";
str.replace("nice","wonderfull"); // this won't work, because I can't replace a String with the method "replace"
// with this method I'm only able to replace charsDoes anyone know some method like I need???
Thanks for your time on answering my question!!
king regards
IceCube-Ddo check java 1.4 api, I think there is a method in it, however for jdk1.3 you can use
private static String replace(String str, String word,String word2) {
if(str==null || word==null || word2 == null ||
word.equals("") || word2.equals("") || str.equals("")) {
return str;
StringBuffer buff = new StringBuffer(str);
int lastPosition = 0;
while(lastPosition>-1) {
int startIndex = str.indexOf(word,lastPosition);
if(startIndex==-1) {
break;
int len = word.length();
buff.delete(startIndex,startIndex+len);
char[] charArray = word2.toCharArray();
buff.insert(startIndex,charArray);
str = buff.toString();
int len2 = startIndex+word2.length();
lastPosition = str.indexOf(word,len2);
return buff.toString(); -
Replace JLabel with a string in JTextPane
Hi all,
anyone knows if there is a way to replace a JLabel with a string in a JTextPane?
The string is contained within the label.
My problem is that when the user is viewing the textpane, he sees a mixed text with strings and labels...but when i save the text, i want to convert the labels in their respective IDs.
Tnx!First you say
"I need to replace JLabel with a JButton"
Then you say
"but i have to change the label of the button as it is being clicked."
So what are you trying to do, just change the text of the button or replace a JLabel with a JButton. We can't give you any help unless you ask a clear question. -
Search given string array and replace with another string array using Regex
Hi All,
I want to search the given string array and replace with another string array using regex in java
for example,
String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
String fromValue[] = {"you", "search", "for", "any"}
String toValue[] = {"me", "dont search", "never", "trip"}
so the string "you" needs to be converted to "me" i.e you --> me. Similarly
you --> me
search --> don't search
for --> never
any --> trip
I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
One Single regular expression which matches the pattern and solve the issue.
the output should be as:
If me wish to don't search never trip etc...,
Please help me to resolve this.
Thanks In Advance,
KathirAs stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
import java.util.regex.*;
public class Test
static final List<String> oldWords =
Arrays.asList("you", "search", "for", "any");
static final List<String> newWords =
Arrays.asList("me", "dont search", "never", "trip");
public static void main(String[] args) throws Exception
String str = "If you wish to search for any of these characters, "
+ "they must be preceded by the character to be interpreted";
System.out.println(doReplace(str));
public static String doReplace(String str)
Pattern p = Pattern.compile("\\b\\w+\\b");
Matcher m = p.matcher(str);
StringBuffer sb = new StringBuffer();
while (m.find())
int pos = oldWords.indexOf(m.group());
if (pos > -1)
m.appendReplacement(sb, "");
sb.append(newWords.get(pos));
m.appendTail(sb);
return sb.toString();
} This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays). -
How to replace the char values into numeric in my string?
Hi Friends,
I would like to Replace the Charecter values with numeric value in my string.
Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
I mean How to replace the char values into numeric in my string?
Thanks,
SridharHi Sridhar,
I would like to Replace the Charecter values with numeric value in my string.
Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
So, if i understand you correctly, you want to replace all characters in a string with 9 as in the above example, irrespective of position of the character, if so try with the below code.
DATA: l_str TYPE string.
l_str = 'ASKHSIUDNSBDKJSDH124312431243124saasdfsf'.
REPLACE ALL OCCURRENCES OF REGEX '\D' IN l_str WITH '9'.
IF sy-subrc EQ 0.
WRITE: l_str. "Result will be 9999999999999999912431243124312499999999
ENDIF.
Regards,
Chen
Edited by: Chen K V on Jun 13, 2011 12:36 PM -
How to replace mixed chars string
Hi All,
I want to replace mixed chars string from each row and want to replace with new string.
Ex : The existing string might be in different cases like "Abc string", "abc string", "aBC string". I want to search for all these string types and want to replace with new string "Abc string".
Could anyone give suggestions on this.
Thanks,
Prakash[url http://download.oracle.com/docs/cd/E11882_01/server.112/e26088/functions149.htm#i1305521]REGEXP_REPLACE supports case insensitive replacing.
REGEXP_REPLACE(source_string,'abc string','Abc string',1,0,'i')The *'i'* specifies case insensitive replacing, so it will find all of "Abc string", "abc string", "aBC string" :-) -
I am adding more memory, should I replace the top two slots with the 4g memory modules, then place 2g memory modules on bottom slots. Does it even matter?
I am adding more memory, should I replace the top two slots with the 4g memory modules, then place 2g memory modules on bottom slots. Does it even matter?
-
How to replace double quotes with a single quote in a string ?
Hi All:
Can some one tell me how to replace double Quote (") in a string with a single quote (') ? I tried to use REPLACE function, but I couldn;t get it worked.
My example is SELECT REPLACE('STN. "A"', '"', ''') FROM Dual --This one throws an error
Thanks,
Dima.Whether it is maybe not the more comfortable way, I like the quoting capabitlity from 10g :
SQL> SELECT REPLACE('STN. "A"', '"', q'(')') FROM Dual;
REPLACE(
STN. 'A'{code}
Nicoals. -
Replacing inconsistant spacing with single space in a string
is it possible to replace multiple spaces within a string with one space only. Number of spaces is different all the time.
say one field contains strings with imbedded spaces
I need to replace all these values so that there will be only one space between words.
For Eg.
Input Expected Result
aaa bbb aaa bbb
ww vv ww vv
ww ss kk ww ss kk
[/code]user11253970 wrote:
I am in Oracle 9i :( I can not use reg exp
Assuming strings do not contain CHR(0) (character with ascii code 0):
SQL> SELECT 'aaa bbb aaa bbb' str,
2 replace(replace(replace('aaa bbb aaa bbb',' ',' ' || CHR(0)),CHR(0) || ' '),CHR(0)) new_str
3 FROM dual
4 /
STR NEW_STR
aaa bbb aaa bbb aaa bbb aaa bbb
SQL> SY. -
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 replace a particular striing with another string in jtextpane
how to get replace a particular string with another string of a jtextpane without taking the text in a variable using getText() method .
Thanks for your answer,
"relevant object" means for you datasources, transfer rules and transformations ?
With the grouping option "Save for system copy" I can't take easily all datasources, and others objects
Will I have to pick all object one by one ?
What would be the adjustement in table RSLOGSYSMAP ? For the moment it's empty.
Regards
Guillaume P. -
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.
Maybe you are looking for
-
ITunes freezes when iPod touch 4G is connected + other issues.
I've seen a lot of people struggling with this problem and I'm afraid I got stuck with the same issue. I'm not sure when it started, but I noticed any time I connected my ipod touch 4G to my computer, iTunes freezes almost immediately. When I disconn
-
My computer is running low on RAM, and when I look at what processes are using the most memory, firefox is the number one using between 28,000 to 93,000k, so I'm guessing that it has a memory leak. And because of that memory leak I have to update fir
-
Mail Receiver Adapter - Flat File as Attachment
Hello, I would like to send a flat file as attachment using an E-Mail receiver communication channel. The flatfile is picked up beforehand using a file sender channel, so there is only routing necessary in PI. Is it possible to send the flatfile as a
-
'Count all rows' in Disco Plus?
Hi all - I can't find an option to Count All Rows in disco plus. This is something my users use all the time in Desktop - is it included in Plus? In Desktop, it is under menu item 'Sheet' Thanks! Scott
-
Printing of pdf document from java application
Hello, I want to print out a pdf document which I get from a server as a byte-stream. I don't want to display or preview it on the client but print it out right away. Is there a way to do this? Thank you very much! Matthias