Count a character within a string
Give a string, what function can I use to count how many a particular character in the string. For example:
"abc;def;ghi;xyz"
I want to find out how many ";" in this string.
Thank you
And of course, if the researched character is not in the given string, then you'll return null, to return 0, you'll need a NVL.even if it is in the string you might need a nvl in Vamsi Kasina's solution:
SQL> select length (';') - length (replace (';', ';')) cnts
from dual
CNTS
1 row selected.Better:
SQL> select nvl(length (';'),0) - nvl(length (replace (';', ';')),0) cnts
from dual
CNTS
1
Similar Messages
-
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 -
Get number of character within a String by number of pixels
How can i get the number of character within a String
by a width value...
for example..
i have a String = "1234567890abcdefghi.........."
and when i give the width "10"
i will get the String "12".
or the number of charcter..
or somthingggggggggggggggg
please help..
Shayi solved this...
by doing somthing similar..
i made a for loop on all character
and evrey time i am get a sub string from the 0 till the loop index..
and i am chashing the last string
so when a sub width is greater the the requested width
i am returning the lst cashed result
thanks.. all.. -
[JS - CS3] Not able to add 'Superscript' style to a character within a string
Hello fellow experts...
I'm stuck with trying to change the style of a character from Normal to Superscript!
b Situation:
I have a string - 'myCourseTitle' - that has both CharacterStyles & ParagraphStyles applyed and could include the following character/Word:
> '®' (Character)
'OperateIT' (Word)
b Requirements:
I am wanting to add the style 'Superscript' to both the '®' characters and 'IT' from the words 'OperateIT', while keeping their initial CharacterStyles & ParagraphStyles!
b My Starting Block:
if (myCourseTitleField.editContents == ""){
var myCourseTitle = "-no title has been defined-";
}else{
var myCourseTitle = myCourseTitleField.editContents;
// The contents should now be checked for '®' characters and 'OperateIT'
// And set to Superscript if found!
if (myCourseTitle.indexOf("®") != 0){
alert("Registered Trade Mark '®' found in Course Title at position:"+myCourseTitle.indexOf("®")+"\rThis will be set to 'Superscript' formatting", "WARNING '®' within Course Title",)
I have tried many scripts, including the attached sample 'FindChangeByList.jsx' script - but to no avail!
Can anyone help me - point me in the right direction to start looking?
Thanks in advance
LeeHi Lee,
In the example, you're trying to apply InDesign formatting to a JavaScript string (from an InDesign dialog box text field). That won't work, because the JavaScript string doesn't know anything about InDesign text objects.
I'm assuming, however, that what you want is to change the formatting of the text on your page. To do that, you can use the findText method on the text, story, or document. Here's an example (the relevant part is the "mySnippet" function--the rest is just setting up an example):
main();
function main(){
mySetup();
mySnippet();
function mySnippet(){
//Clear find text preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = "®";
app.changeTextPreferences.appliedCharacterStyle = app.documents.item(0).characterStyles.item("superscript");
app.documents.item(0).changeText();
//Reset find/change text preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Reset find/change GREP preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//There's probably a way to do this in a single pass, but I'm short on time...
app.findGrepPreferences.findWhat = "\\l(?<=)IT";
app.changeGrepPreferences.appliedCharacterStyle = app.documents.item(0).characterStyles.item("superscript");
app.documents.item(0).changeGrep();
app.findGrepPreferences.findWhat = "\\l";
app.findGrepPreferences.appliedCharacterStyle = app.documents.item(0).characterStyles.item("superscript");
app.changeGrepPreferences.appliedCharacterStyle = app.documents.item(0).characterStyles.item("[None]");
app.changeGrepPreferences.position = Position.normal;
app.documents.item(0).changeGrep();
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//mySetup simply takes care of setting up the example document.
function mySetup(){
var myDocument = app.documents.add();
var myPage = app.activeWindow.activePage;
//Create a text frame on page 1.
var myTextFrame = myPage.textFrames.add();
//Set the bounds of the text frame.
myTextFrame.geometricBounds = myGetBounds(myDocument, myPage);
//Fill the text frame with placeholder text.
myTextFrame.contents = TextFrameContents.placeholderText;
myTextFrame.insertionPoints.item(0).contents = "OperateIT®\r";
myTextFrame.paragraphs.item(-1).insertionPoints.item(0).contents = "OperateIT®\r";
var myHeadingStyle = myDocument.paragraphStyles.add({name:"heading"});
var mySuperscriptStyle = myDocument.characterStyles.add({name:"superscript", position:Position.superscript});
function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
Thanks,
Ole -
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 -
Count of character in a string
Hi,
Here is a string.
Str = 'test,123,1-Jan-2008',sql,oracle,test,date
Can we count the number of commas(,) in the above string without passing it to any loop? I want to use replace/translate and length for this purpose.
Regards,
RiteshSQL> var a varchar2(500)
SQL> exec :a := '''test,123,1-Jan-2008'',sql,oracle,test,date'
PL/SQL procedure successfully completed.
SQL> print a
A
'test,123,1-Jan-2008',sql,oracle,test,date
SQL> select length(:a)-length(replace(:a,',')) comma_count
2 from dual
3 /
COMMA_COUNT
6 -
Counting particular character in a string
Hi all
how can we count the number of characters in a perticular string in simple SQL statement
example
how many commas are there in this string 'a,b,s,d,e,f,g,h'select length('a,b,c,d,e')-length(replace('a,b,c,d,e',','))
from dual -
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> -
Unable to use character within a String in a skeleton file
The < character appears to be a special character to skeleton files. I am unable to use this character to built a string in a skeleton file.
For instance, using this block:
<jsp:scriptlet>
String sample = "<test";
</jsp:scriptlet>
Results in this error: String literal is not properly closed by a double quote.
It's also not allowed as a character either:
<jsp:scriptlet>
String sample = "[test";
sample = sample.replace('[','<');
</jsp:scriptlet>
This block has the error: Invalid character constant.
It appears the < character is a special character in the way skeleton files parse, but I can't find any way to escape it like normal special characters.That actually puts < into the string, which the browser won't interpret as HTML.
This also breaks the Workshop UI saying the string literal isn't terminated. It doesn't like & or ; characters in strings either. However, it will still compile and run.
Edited by btiminey at 01/31/2008 8:34 AM
Edited by btiminey at 01/31/2008 8:35 AM -
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 -
NewLine Character in the String received from Interactive Adobe Form
Hello Experts,
Following is the issue we have with interactive Adobe Form
We have a text area within the form. User enters the text in multiple lines in this text area.
We are calling a backend function module designed in SE37 that accepts and process the data from the adobe form. We are also processing the string data user enters in the text area.
When we receive the string from the form, the newline character within the string is displayed as '#' in the debugger. We tried splitting this string using cl_abap_char_utilities=>newline and cl_abap_char_utilities=>cr_lf but NO luck. Though in the debugger we see cl_abap_char_utilities=>newline as '#' in the debugger and also '#' is present within the string, for some reason when string is processed to find cl_abap_char_utilities=>newline, we can find/locate it.
Because ABAP code is not able to identify the newline character within the string received from Adobe form, we are not able to maintain the formatting of the string as it was entered in the form.
Any help to resolve this issue is appreciated.
Thanks in Advance.
Regards,
BhushanHi Bhushan,
I was going through your issue, and I feel this is something you can do with scripting. Basically you should read whole string and find the new line character and replace with a space or comma, as per your requirment.
Do like following:
In the exit event of the field select java script and write following code:
var strng = this.rawValue;
strng.replace(/\n/g, " ");
above im reaplcing new line with a space.
I think it should work I have not tested it. Pls update if you test it .
Regards,
Ravi.D -
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 -
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
-
Please read my problem when I configure Weblogic https
I want to use https protocol and SSL for my web application in Weblogic I have a problem but I am not sure it's related to configuring Weblogic or not please if you can advice me I use "openssl" to be my own Certificate Authority (CA) I used this ins
-
Access denied errors in domain logs after configuring Ldap and restricting access to users
Hi Experts, I'm getting access denied errors in my domain logs , this log is written continiously ..Has any one encountered the same issue and fixed this? ####<Sep 2, 2014 2:30:07 PM EDT> <Error> <Default> <ftizsldmwapp001.ftdc.cummins.com> <AdminSer
-
After installing ABAP Trial Version NW7 on my laptop, I copied ref client 000 to two clients (100 and 200), and set up a person business partner on each client with parnter number 1. I then delegated BUS1006 on system 100 so that I had a YBUS1008 ob
-
I can't seem to locate a time zone setting for Adelaide South Australia on my nano. It's available as a city on the clock but not for me to select as my time zone...am i missing something here!?! Cheers, Neil
-
Info abt developing iphone Apps
helow am a software engg student i want to develop an iphone application as a project.... can ne1 plz guide me the procedure..... abt its sdk?? do i 've to get MAC for it..or can be done on windows..??? ??