Hi, Occurrences Of Every Character In A String
Hi All,
I want to write a program wherein I can check the occurrences of every character in the string given.
What should I do, is there a in built function to do this.
Please help
I wrote this program and this works fine... Thanks
public class Main_Character_Occurence
public static void main(String args[])
String inputString = " Test String";
String matches = "abcdefghijklmnopqrstuvwxyz";
int sum = 0;
for (int i = 0; i < matches.length(); i++)
for (int ctr = 0; ctr < inputString.length(); ctr++)
if (matches.charAt(i) == Character.toLowerCase(inputString
.charAt(ctr)))
sum++;
System.out.println(matches.charAt(i) + "=" + sum);
sum = 0;
}The output I am getting is this
a=0
b=0
c=0
d=0
e=1
f=0
g=1
h=0
i=1
j=0
k=0
l=0
m=0
n=1
o=0
p=0
q=0
r=1
s=2
t=3
u=0
v=0
w=0
x=0
y=0
z=0
Similar Messages
-
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 -
Read every character in a string
Hi,
I want to read every charater in a string and if I find a special character(¿) then want to replace with replace it with(°) symbol. length of the characters are not fixed.
Please advise.
Regards,
Arnie.user558927 wrote:
Hi,
I want to read every charater in a string and if I find a special character(¿) then want to replace with replace it with(°) symbol. length of the characters are not fixed.
Please advise.
Regards,
Arnie.There's built in functionality for that.
http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions153.htm#SQLRF00697
Cheers, -
Occurence of character in a string
How can i find how many occurrence of a character in a string?
Let's say: 010101010101010: there is 8 0 in that string.Here's just a different take on the same old problem, tested on 10g ... ;-)
WITH t AS (SELECT '010101010101010' col1
FROM dual
SELECT SYS_CONNECT_BY_PATH(symbol || ':' || TO_CHAR(no_of_sym), ' ') sym_stat
FROM (SELECT SUBSTR(t.col1, LEVEL, 1) symbol
, COUNT(*) no_of_sym
, ROW_NUMBER() OVER (ORDER BY SUBSTR(t.col1, LEVEL, 1)) rn
FROM t
CONNECT BY LEVEL <= LENGTH(t.col1)
GROUP BY SUBSTR(t.col1, LEVEL, 1)
WHERE connect_by_isleaf = 1
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
=> "0:8 1:7"C. -
OBIEE - Find position of the last occurrence of a charcter within a string.
Hi,
I have a requirement in 11.1.1.6.9 to be locate the position of the last occurrence of a character within a string.
i.e. Given the following, I would want to locate the last "/":
This/is/an/exampleI would like to return a value of 11. Now, there could be any number of "/" so I can't always locate the nth one - it must be the last one.
Anyone any ideas?
Thanks,
JohnYour requirement is not complete. just in case you want to extract the last part 'example' just use substring and replace to trim up to required part.
You may have to go for the same for multiple times.
ETL is the best to handle this than BI.
BTW: Check this How to use locate function if multiple occurences of same character
Edited by: Srini VEERAVALLI on May 10, 2013 10:25 AM
Good that given link is helped you to solve it ;)
Edited by: Srini VEERAVALLI on May 13, 2013 7:47 AM -
Replacing first Character of every word in a string with an Uppercase
Hi,
Is it possible to replace all first character of every word in a string with UpperCase?
$="autocad lite"
Should look "Autocad Lite" .
Thanks,
FrançoisHi FRacine,
Please refer to the script below:
$givenname="autocad lite"
$givenname
$givenname = $givenname.substring(0,1).toupper()+$givenname.substring(1)
$givenname
Edit: to change first character in every word, please refer to this script, this may not be the best way, but it can work:
$givenname="autocad lite"
$givenname
$words=$givenname.split(" ")
$givenname=""
foreach ($word in $words){
$givenname+=$word.substring(0,1).toupper()+$word.substring(1)+" "}
$givenname=$givenname.trim()
$givenname
If there is anything else regarding this issue, please feel free to post back.
Best Regards,
Anna Wang -
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 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... -
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. :-) -
BufferedReader Problem (inserting space after every character)
(This is a message I sent to an Aglet forum, however I thought maybe someone here could help me with the BufferedReader problem...with the spacing...read below)
-Blake
ok here's what I'm attempting to do.
I have a Master Aglet that creates a slave which is dispatched to a remote site. The Slave then opens a log file, reads it, and then is supposed to read the file line by line and send each line as a message back to the Master. As the master receives each line it appends the line to the window it created earlier.
I don't know what the problem is...it won't display the log file in the master window.
It does display each line on the console window.I added a println() function to make sure the String array was getting the information. There is a small problem with that as well because it inserts a space after EVERY character (BufferedReader problem??)...what is up with that? for example:
If the log file looked like: This is a log file entry.
the console looks like this when it is printed: T h i s i s a l o g f i l e e n t r y .
.... I had done something in a similiar program...and it worked just fine. here's some source code:
<b>Master:</b>
else if (msg.sameKind("Log")) {
try {
//println for testing purposes
System.out.println(msg.getArg());
appendMessage(" " + msg.getArg() + "test \n");
} catch (Exception e) {
System.out.println(e.toString());
<b>Slave: </b>
File log = new File("C:\\Aglets2.0.2\\public\\WINDOWSUPDATE.log");
FileReader fr = null;
try{
fr = new FileReader(log);
} catch (FileNotFoundException e) {
System.out.println(e);
BufferedReader br = new BufferedReader(fr);
//Get filename of log
try {
Message msg = new Message("FileName", log.getName());
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
//read each line of file and send back to Master as a message
try{
int i = 0;
while ((s = br.readLine()) != null) {
i++;
count = i;
for (int j = 0; j < count; j++)
System.out.println(s[j]);
//send message back to Master Aglet with log file information
try {
Message msg = new Message("Log", s[j]);
mProxy.sendMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
//close file reader
fr.close();
} catch (IOException e) {
System.out.println(e.toString());
}actually i did declare s, you just don't see it there because i only posted some of the code....
I fixed the "spacey" problem by using a FileInputStream instead of a bufferedreader....
like this (i'll post the whole code here:
public class Slave extends BlindAglet {
AgletProxy mProxy = null;
boolean back = false;
char[] c = new char[1000];
BufferedReader br = null;
int count;
// Do some tasks when the aglet is created
public void onCreation(Object init) {
// Must make a note of the master here
mProxy = (AgletProxy)init;
// Add our own listener and adapter
addMobilityListener(
new MobilityAdapter() {
// Using this as a safety check in case we get caught in a loop in the same host
public void onArrival(MobilityEvent event) {
try {
mProxy.sendMessage(new Message("NewSlaveProxy", getAgletContext().getAgletProxy(getAgletID())));
} catch (InvalidAgletException iae) {
System.out.println(iae);
} catch (NotHandledException ex) {
System.out.println(ex);
} catch (MessageException ex) {
System.out.println(ex);
//Are we back to origin?
if(back) {
back = false;
try{
FileWriter fw = new FileWriter("test.txt");
for (int i = 0; i < count; i += 2){
fw.write(c);
fw.close();
} catch (IOException e) {
System.out.println(e);
dispose();
dispose();
); /* End of Adapter */
public void run() {
// Are we at home base?
if (atHome()) {
try {
dispatch(new URL("atp://darklord:4434"));
} catch (Exception e) {
System.out.println(e.toString());
try{
File log = new File("C:\\Aglets2.0.2\\public\\WINDOWSUPDATE.log");
FileInputStream f0 = new FileInputStream(log);
//Get filename of log
try {
System.out.println(log.getName());
Message msg = new Message("FileName", log.getName());
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
//read each line of file and send back to Master as a message
try{
int size = f0.available();
int i = 0;
for (i = 0; i < size; i++) {
c[i] = (char) f0.read();
//send message back to Master Aglet with log file information
try {
Message msg = new Message("Log", c[i]);
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
count = i;
} catch (IOException e) {
System.out.println(e.toString());
} catch (FileNotFoundException e) {
System.out.println(e);
back = true;
returnHome();
* Returns true if the current host is our origin
public boolean atHome() {
if (getAgletInfo().getOrigin().equals(getAgletContext().getHostingURL().toString()))
return true;
else
return false;
* Allows a slave to contact it's master and ask for a retraction.
public void returnHome() {
try {
Message msg = new Message("RetractMe");
msg.setArg("url", getAgletContext().getHostingURL());
msg.setArg("id", getAgletID());
mProxy.sendOnewayMessage(msg);
} catch (InvalidAgletException iae) {
System.out.println(iae.toString());
} catch (Exception e) {
System.out.println(e.toString());
* Return a reference to our Master's proxy
public AgletProxy getMasterProxy() {
return mProxy;
} /* End of Class -
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. -
Incrementing every letter in a string that occupies an odd position.
Hi, for an "encryption" project, i need your help creating a method that will be incrementing by 5 every char in a string that occupies an odd position in that same string.
For example : 'adam' should return 'aiar'
-Method can't use arrays.
-Method can't use regular expressions like 'split' etc..in order words the teacher wants us to use the simplest stuff inside the String class.
-Only letters must be modified.
so far i have this : (names of values are in french, sorry)
public class Main {
public static String incrementerDeCinqImpaires (String chaine) {
char j = chaine.charAt(1);
char x = chaine.charAt(3);
char o = chaine.charAt(5);
j+=5;
x+=5;
o+=5;
System.out.println(x);
System.out.println(j);
System.out.println(o);
String tmpString = chaine.replace( chaine.charAt(1), j );
String tmpString2 = tmpString.replace( tmpString.charAt(3), x );
String tmpString3 = tmpString2.replace( tmpString2.charAt(5), o );
System.out.println( "Original = " + chaine );
System.out.println( "Result = " + tmpString3 );
return tmpString3;
public static void main (String args [] ) {
System.out.println (incrementerDeCinqImpaires("adam"));
}The thing is i need a "for" loop (which has been a nightmare for me trying to figure out how to make it) in order to increment every odd positioned char in the string.
So all I need really is to sum up what i posted above inside a for loop (or more). Then just add ifs and elses so i can increment only letters.I don't think String.replace will do what you want. What happens when a single letter appears in an even-numbered position and then in a later odd-numbered position?
Can you use StringBuilder?
Or you can do a bunch of String appends (i.e., use StringBuilder implicitly), one character at a time, in a loop.
By the way you haven't done the part where you check that the character is a letter.
Also, what do you do with the last five letters of the alphabet? (Regardless of the alphabet you're using.) You could end up inserting control characters or characters that you can't print in your locale. Do you wrap? -
Correct way to search for character within a string
I am trying to search for the occurrence of a "(" within a text string - unfortunately my code is reported as incorrect.
I extract the text correctly but cannot create the search statement correctly:
var mylistpgftext = pgf.GetText (Constants.FTI_String)
for (var i=0; i < mylistpgftext.length; i++)
var mylistitem = mylistpgftext[i].sdata
var mybracketpos = mylistitem.search(/(/i) --------------error line-----------------
if (mybracketpos != -1)
alert(mylistitem)Hi Bob, I did not test this, but I think the problem is an unescaped character in your regular expression. Try this.
var mybracketpos = mylistitem.search(/\(/i);
Notice the backslash before the open parens that you are searching for.
-Rick -
How to moniter and Replace every character typed into a JTextArea!
I have a JTextArea!
For every character typed on it in want to change that character to my own character...
For example if user types 'a' on key board, i want 'b' to be displayed on the JTextArea.
It should been seen on the screen...
Any idea?
P.N: I am doing a notepad like editor where in user can type Indic languages in phonetic notation... [Yea, Transliteration....] Does any one have any coding for that, Especially for Tamil... I want to get அம்மா, if i type "amma". I have the table of what should be replace with what! but i don't know how to make it work? any idea?if user types 'a' on key board, i want 'b' to be displayed on the JTextArea.Add a KeyListener and override the keyTyped method to increment the keyChar field of the KeyEvent.
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class KeyShifter {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new KeyShifter().makeUI();
void makeUI() {
JTextArea textArea = new JTextArea();
textArea.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char c = (char) (ke.getKeyChar() + 1);
ke.setKeyChar(c);
JFrame frame = new JFrame("Key Shifter");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.add(textArea);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
So maybe it'd be better to have two text fields... one what was typed (as per normal) and a JTextArea to display the transliterated text. Just an idea.And a very good idea, Keith... just testing this was creepy! Yup, this could be recoded to append a character other than the one typed, to a second, uneditable, text area. I'd use a Map or some other data structure to get the transliterated character from the one typed.
db -
[AS] Set every character leading to auto
I can't seem to get this to do what I expect.
tell application "Adobe InDesign CS5.5"
tell every text frame of page 1 of active document
set leading of properties of every character of every paragraph to auto
end tell
end tell
The script I am working on imports text. Everything works except the leading, it comes in with "0 pt" leading and I need the script to basically check every character on the page and if the leading is 0 set it to auto.... I put this together as a quick and dirty test to try and make it work and in no way represents the final code.
Everything I have tried has either done nothing or gives me an error saying "Expected number, string or auto" when I give it auto.
I don't care if it is AS or JS as long as it works.The problem is that some text comes in with the leading set properly and some doesn't. Only when the leading is set to 0 should it adjust it to auto.
I also need the 'do script' because this is a single line in a very large script written almost entirely in Applescript.
The project I am working on takes documents made in MultiAd Creator and migrates them to Indesign. We are phasing out the other product and using only Adobe. The entire archive of old documents needs to be migrated over to indesign.
The script currently will get about 80% of that correct. The leading was one of the minor issues. There is something like 4000 documents to be migrated over and the script needs to pretty much do it without interaction and get the new document to be 100% exact to the old document.
It works like this:
The script navigates the entire server finding Creator documents.
Opens each in turn in Creator.
Creates a new InDesign document of the same dimensions.
Every color in the Creator document is add to the swatches in InDesign.
Then every shape object is recreated point by point in the InDesign document. (this includes the placed graphics)
All text flows in the Creator document are recreatedas text frames in the InDesign document.
Everything is adjust so that layering is correct.
The new Indesign document is then saved in the same location as the Creator document using the same name.
Creator handles fonts differently than Indesign. Instead of using italics or bold from the font family it would apply stroke or skew the text. I have that nearly sorted out so that it works nearly perfectly, but the leading was not coming over properly 100% of the time.
What I thought should work wasn't and that was bugging me as one of those "I'll come back to it later" things I hadn't come back to yet.
Maybe you are looking for
-
Hi Experts I have one request in DSO in my Development system whose request is not activating, not even giving any message. I tried with delete and reload but not working. please suggest some ideas.
-
Is it possible to read information off the desktop and send it to java ?
Hello. I am wondering if it's possible with Java to read information off the screen and send it to a java listener to be interpreted. information such as comparable images (ie images that you can match with an image you already posess in order to cla
-
Big issue with decimal separator
regional settings of machine where client & server reside are for european country (decimal separator is ",") sap b1 decimal separator is set also for ",". exception occurs when I set in code, for a edittexts' datasource of type SUM a decimal value u
-
Hi all, Spotlight seems to reindex the entire hard drive with each restart. Often takes 20 minutes; slows the machine down to a crawl; cranks the CPU temperature to 170F, while the fan stays on for the entire time. Should Spotlight reindex with each
-
Infotype 552 Years of Service Calculation Error
Good day, Has anybody experienced an error in IT552 when calculating years of service? We have an associate that hired in on 04-01-1985 and retired on 12-31-2006. The years of service calculates as 21 years 9 months and 0 days. If I calculate this