Count the repeated character in a string
Hi Great Gurus,
Please tell me how to know how many times a given character repeats in a string.
Please mail me .
Thanks Gurus,
Rahul
hi,
same thread----
Re: find number of occurances of a particular character
data: var1(30) type c value 'ghghj#ghjgjgh#ghjghjg#ghjg#'.
data : totcnt type i,
cnt type i,
v type c,
n type i.
cnt = strlen( var1 ).
do cnt times.
move var1+n(1) to v.
if v eq '#'.
totcnt = totcnt + 1.
endif.
n = n + 1.
if n = cnt .
exit.
endif.
enddo.
write:/ 'No of #s', totcnt .
Regards
Reshma
Similar Messages
-
How to find out the repeated character in a string value?
Dear People,
I want to trace out the names where a character occured more than once.for ex, i need o/p as
ENAME
ALLEN
TURNER
ADAMS
In which all the above name consists of repeated characters.
I use Oracle 10g and i tried using REGEXP say for ex,
SELECT ENAME FROM EMP WHERE REGEXP_LIKE(ENAME,'L{2}');
ENAME
ALLEN
MILLERbut this works only for single character.how to specify condition for any character?.pls suggest me.
With Regards
VIDSHere is one way you can use from version 10 upwards:
SQL> with emp as
2 ( select 7369 empno, 'SMITH' ename, 'CLERK' job, 7902 mgr, date '1980-12-17' hiredate, 800 sal, NULL comm, 20 deptno from dual union all
3 select 7499, 'ALLEN', 'SALESMAN', 7698, date '1981-02-20', 1600, 300, 30 from dual union all
4 select 7521, 'WARD', 'SALESMAN', 7698, date '1981-02-22', 1250, 500, 30 from dual union all
5 select 7566, 'JONES', 'MANAGER', 7839, date '1981-04-02', 2975, NULL, 20 from dual union all
6 select 7654, 'MARTIN', 'SALESMAN', 7698, date '1981-09-28', 1250, 1400, 30 from dual union all
7 select 7698, 'BLAKE', 'MANAGER', 7839, date '1981-05-01', 2850, NULL, 30 from dual union all
8 select 7782, 'CLARK', 'MANAGER', 7839, date '1981-06-09', 2450, NULL, 10 from dual union all
9 select 7788, 'SCOTT', 'ANALYST', 7566, date '1982-12-09', 3000, NULL, 20 from dual union all
10 select 7839, 'KING', 'PRESIDENT', NULL, date '1981-11-17', 5000, NULL, 10 from dual union all
11 select 7844, 'TURNER', 'SALESMAN', 7698, date '1981-09-08', 1500, 0, 30 from dual union all
12 select 7876, 'ADAMS', 'CLERK', 7788, date '1983-01-12', 1100, NULL, 20 from dual union all
13 select 7900, 'JAMES', 'CLERK', 7698, date '1981-12-03', 950, NULL, 30 from dual union all
14 select 7902, 'FORD', 'ANALYST', 7566, date '1981-12-03', 3000, NULL, 20 from dual union all
15 select 7934, 'MILLER', 'CLERK', 7782, date '1982-01-23', 1300, NULL, 10 from dual
16 )
17 select ename
18 , e
19 , count(*)
20 from ( select ename
21 , e
22 from emp
23 model
24 return updated rows
25 partition by (ename)
26 dimension by (0 i)
27 measures (ename e)
28 ( e[for i from 1 to length(e[0]) increment 1] = substr(e[0],cv(i),1)
29 )
30 )
31 group by ename
32 , e
33 having count(*) > 1
34 /
ENAME E COUNT(*)
SCOTT T 2
MILLER L 2
ADAMS A 2
ALLEN L 2
TURNER R 2
5 rows selected.Regards,
Rob. -
To count the repeated entries in a XML document.
HOW TO COUNT THE REPEATED NUMBER OF ENTRIES IN A XML DOCUMENT USING THE SAP REPORT PROGRAM?
<?xml version="1.0" encoding="utf-16" ?>
- <ROOT>
- <SYSTEMDETAILS>
- <item>
<SYSDETAILSNAME>CODE</SYSDETAILSNAME>
<SYSDETAILS>00</SYSDETAILS>
</item>
- <item>
<SYSDETAILSNAME>LICENSE</SYSDETAILSNAME>
<SYSDETAILS>INITIAL</SYSDETAILS>
</item>
- <item>
<SYSDETAILSNAME>BASIS RELEASE</SYSDETAILSNAME>
<SYSDETAILS>700</SYSDETAILS>
</item>
- <item>
<SYSDETAILSNAME>SYSTEM NAME</SYSDETAILSNAME>
<SYSDETAILS>IS3</SYSDETAILS>
</item>
- <item>
<SYSDETAILSNAME>CLIENT</SYSDETAILSNAME>
<SYSDETAILS>800</SYSDETAILS>
</item>
- <item>
<SYSDETAILSNAME>LOCLANG</SYSDETAILSNAME>
<SYSDETAILS>English</SYSDETAILS>
</item>
</SYSTEMDETAILS>
- <ACH>
- <item>
<NAME>HLA0009999</NAME>
<TLEVEL>01</TLEVEL>
<TEXT>SAP</TEXT>
<TEXT4>Application Components</TEXT4>
<TEXTLOC>Application Components</TEXTLOC>
</item>
<item>
<NAME>ABA0000311</NAME>
<TLEVEL>02</TLEVEL>
<TEXT>AP</TEXT>
<TEXT4>Application Platform</TEXT4>
<TEXTLOC>Application Platform</TEXTLOC>
</item>
- <item>
<NAME>KPE0000001</NAME>
<TLEVEL>03</TLEVEL>
<TEXT>AP-PPE</TEXT>
<TEXT4>Integrated Product and Process Engineering</TEXT4>
<TEXTLOC>Integrated Product and Process Engineering</TEXTLOC>
</item>
SAY THE BOLD PART SHOWS 1 USER ,SO HOW MANY TIMES THE SAME USER APPEARS IN THE DOCUMENT.
HOW CAN I FIND THAT?If the same content of file already thr in the Internal table as 1 STRING/LINE then you can loop the internal table count the entries which one you want like
Kanagaraja L -
Strip the first character from a string
i am trying to strip the leftmost character from a string
using the following:
<cfset Charges.DTL_CHG_AMT_EDIT =
#Right(Charges.DTL_CHG_AMT_EDIT,Len(Charges.DTL_CHG_AMT_EDIT)-1)#>
i keep getting the following error:
Parameter 2 of function Right which is now -1 must be a
positive integer> RemoveChars() much easier than Right()? How so?
Semantically, if the object of the exercise is to *REMOVE
CHARacters from a
string* (which it is, in this case), it is simply better
coding to use
removeChars() rather than right(). That, and it's one less
function call
(the RIGHT() solution also requires a call to LEN() for it to
work).
So removeChars() is "easier" because it reflects the intent
of the exercise
directly, is simpler logic, is easier to read, and - I can't
be arsed
counting keystrokes - is probably less typing.
That'd be how.
Adam -
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 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)); -
Testing the last character of a string using .endsWith
Hi,
I want to check to see if the last character of a string is '@'.
I tried if (StringAt.endsWith("a")) {
but got no results.
Is this the correct way to do it or is there another way.
Thanks.
Adamjavadocs:
String's endsWith method takes a string argument.
endsWith
public boolean endsWith(String suffix)
Tests if this string ends with the specified suffix.
Parameters:
suffix - the suffix.
Returns:
true if the character sequence represented by the argument is a suffix of the character sequence
represented by this object; false otherwise. Note that the result will be true if the argument is the
empty string or is equal to this String object as determined by the equals(Object) method.
Throws:
NullPointerException - if suffix is null. -
Fastest way to count the number of occurences of string in file
I have an application that will process a number of records in a plain text file, and the processing takes a long time. Therefore, I'd like to first calculate the number of records in the file so that I can display a progress dialog to the user (e.g. " 1234 out of 5678 records processed"). The records are separated by the string "//" followed by a newline, so all I need to do to get the number of records is to count the number of times that '//' occurs in the file. What's the quickest way to do this? On a test file of ~1.5 Gb with ~500 000 records, grep manages under 5 seconds, whereas a naive Java approach:
BufferedReader bout = new BufferedReader (new FileReader (sourcefile));
String ffline = null;
int lcnt = 0;
int searchCount = 0;
while ((ffline = bout.readLine()) != null) {
lcnt++;
for(int searchIndex=0;searchIndex<ffline.length();) {
int index=ffline.indexOf(searchFor,searchIndex);
if(index!=-1) {
//System.out.println("Line number " + lcnt);
searchCount++;
searchIndex+=index+searchLength;
} else {
break;
}takes about 10 times as long:
martin@martin-laptop:~$ time grep -c '//' Desktop/moresequences.gb
544064
real 0m4.449s
user 0m3.880s
sys 0m0.544s
martin@martin-laptop:~$ time java WordCounter Desktop/moresequences.gb
SearchCount = 544064
real 0m42.719s
user 0m40.843s
sys 0m1.232sI suspect that dealing with the file as a whole, rather than line-by-line, might be quicker, based on previous experience with Perl.Reading lines is very slow. If your file has single byte character encoding then use something like the KMP algorithm on an BufferedInputStream to find the byte sequence of "//\n".getBytes(). If the file has a multi-byte encoding then use the KMP algorithm on a BufferedReader to find the chars "//\n".getCharacters() .
The basis for this can be found in reply #12 of http://forum.java.sun.com/thread.jspa?threadID=769325&messageID=4386201 .
Edited by: sabre150 on May 2, 2008 2:10 PM -
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. -
Want to single out the last character of a string
There is a field where there are many strings of varying length. E.g.: AB001XUV, AB003XUK, DJ8933FXUV etc.
From these strings I need to create a virtual column where only the last character is shown. So it shall be V, K, V for values from the above example.
Can anyone please suggest me how to achieve this.
Regards
HawkerSQL> with t as (
2 select 'AB001XUV' col from dual
3 union
4 select 'AB003XUK' col from dual
5 union
6 select 'DJ8933FXUV' col from dual
7 )
8 select substr(col,-1,1) from t
9 /
S
V
K
V
SQL> create table temp(id number,
col varchar2(10),
VIRTUAL_COL VARCHAR2(1) GENERATED ALWAYS AS (substr(col,-1,1)) VIRTUAL
SQL> insert into temp(id,col) values(1, 'AB001XUV') ;
SQL> select * from temp ;
ID COL V
1 AB001XUV V
SQL> Edited by: Azhar Husain on Aug 16, 2011 1:17 PM -
The last character of a string
How to judge the last char of a string is " ?
if (s.endsWith("""))or
if (s.endsWith("/""))bet
you just copied and pasted what the OP had written
and quickly put that
backslash in, hit post without previewing first just
to make me look like
a slow old sod! It's not fair ;-)
kind regards,
JosNope, I used the Alt-[numeric code] combinations to manually type each character. Cut-n-paste is for wimps, and actually typing single-stroke keys is for milquetoasts.
Alt-[numeric code] is for real men ;-) -
How to get the numeric character in a string
Hi Experts,
I have the following requirement.
I am double clicking on the number of a string and I need to get the number as the output.
I have string like
String1 : "Account Number 19292 is closed" I am double clicking on 19292
I want the output as 19292
String2 : "AccountNumber19292isclosed" I am double clicking on 19292
I want the output as 19292
String3: "Account Number1929 2 isclosed" I am double clicking on 1929
I want the output as 1929 and not 19292
String4 :"Account Number 1929 2is closed" I am double clicking on 2
I want the output as 2.
Thanks in Advance,
RajuHi Raju,
All possible solutions should more or less do the following two steps:
<ol>
<li>Check if at the given offset is a number: If yes, retain all consecutive numeric characters from the offset; otherwise stop.</li>
<li>Retain any consecutive numeric characters preceding the number at the given offset and remove all other characters</li>
</ol>
Pretty trivial stuff, but the interesting challenge is actually to come up with the solution with least amount of coding (and ideally still understandable). I have a solution that is pretty short, though not really obvious for people not knowing about regular expressions...
So here's the coding (relevant part in the form) and a quick test harness to check out what it does:
data:
TXT type STRING,
NUM type STRING,
OFF type I,
LEN type I.
TXT = '0Account12 Number 345 6 78isclosed9.9'.
LEN = strlen( TXT ).
do LEN times.
OFF = SY-INDEX - 1.
perform EXTRACT_NUMBER using TXT
OFF
changing NUM.
write: /(3) OFF, ':', (5) NUM, TXT(OFF) inverse no-gap, TXT+OFF.
enddo.
* Return number at given offset in string (empty if no number present)
form EXTRACT_NUMBER using TXT type STRING
VALUE(OFF) type I
changing NUM type STRING.
NUM = TXT.
replace regex '^(\d+).*$' in section offset OFF of NUM with '$1'.
if SY-SUBRC = 0.
replace regex '^.*[^\d](\d*)$' in NUM with '$1'.
else.
NUM = ''.
endif.
endform.
I think this should match your requirements. Let's see if somebody comes up with a solution with less lines...
Cheers, harald -
Replace the first character in a String with blank
String a = dgramRsp.getAddress().toString();
a = a.replace('/','');The problem with the first statement is that it returns an ip address with a '/' in front of it. Like so.../192.168.0.190
I need to get rid of the '/'. The replace won't work because it wants a character between the ' '. Thanks for your time.I had to think about it for a sec but yes you're
right.
InetAddress a = dgramRsp.getAddress();
String b = a.getHostAddress();
substring(1) would have worked, too, but it would have been redundant (removing a previously added slash). -
Counting a Special Character from a String
Hello,
I have a String let say 'ABC-X', 'ABC-X-Y' ....
so how can we find the count/No. of Hypen('-') .. in a string....I have a String let say 'ABC-X', 'ABC-X-Y' ....
so how can we find the count/No. of Hypen('-') .. in a string....
SQL> var str varchar2(20);
SQL> exec :str := 'ABC-X-Y';
PL/SQL procedure successfully completed.
SQL> select length(:str) - nvl(length(replace(:str,'-')),0) from dual;
LENGTH(:STR)-NVL(LENGTH(REPLACE(:STR,'-')),0)
2
SQL> -
Writing plsql function to find out repeating character in a string
I need to write one pl sql function to compare 2 consecutive character in a word that they are same or not, if same return false otherwise return true. could any one help me on this
what i have written pasting here code or make me correct
CREATE OR REPLACE FUNCTION validate_password (v_string IN VARCHAR2)
RETURN BOOLEAN
IS
v_number NUMBER (3) := 1;
i_length NUMBER (3);
BEGIN
SELECT LENGTH (v_string) INTO i_length FROM DUAL;
IF (i_length > 0)
THEN
FOR v_number IN v_number .. i_length
LOOP
substring (v_string, v_number, 1) :=
substring (v_string, v_number + 1, 1);
v_number := v_number + 1;
END LOOP;
END IF;
RETURN v_string;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('message');
END;
Thanks in advance.no need to SELECT FROM DUAL;
How do I ask a question on the forums?
SQL and PL/SQL FAQ
scroll down to #9 to see how to use tags as below
[code]
CREATE OR replace FUNCTION Validate_password (v_string IN VARCHAR2)
RETURN BOOLEAN
IS
v_number NUMBER (3) := 1;
i_length NUMBER (3);
BEGIN
i_length := Length (v_string) ;
IF ( i_length > 0 ) THEN
FOR v_number IN v_number .. i_length LOOP
Substring (v_string, v_number, 1) :=
Substring (v_string, v_number + 1, 1)
v_number := v_number + 1;
END LOOP;
END IF;
RETURN v_string;
EXCEPTION
WHEN OTHERS THEN
dbms_output.Put_line ('message');
END;
[/code]
Maybe you are looking for
-
I forgot the answers of the security questions.
I bought an iTunes card, but I can't used it cause when I try to buy it tells me to answer the security questions, but I forgot them. I sent the information to the email, but the email does not arrive, I already checked all the mailboxes. Now I can't
-
How to use iphone 5 with gloves
I'd like to know how to use the iphone 5 with motorcycle-gloves.
-
Hello, Is it possible to upgrade the CSACS-1121-UP-K9 to be a non upgrade part? We were going to upgrade from a Windows 4.x to the above Appliance (version 5.x) but there is now a reason to keep the old Windows version running ther
-
EssMdxTrig API and EssMdxExecuteQuery(), EssMdxNewQuery() APIs
Hi, I want to maintain Change Data Capture for an Essbase outline/cube. I want to write a on-update trigger in sucha way so that it executes everytime when any new data load happens in the Essbase cube. This trigger should create a spool file and sho
-
HT4061 Having issues updating apps
Having issues updating apps on my Iphone5, can anyone help?