Searching for a substring within a string
can someone reccomend a simple way to search for a substring within a string and count the number occurences of that substring.
The substring and the string will be provided as command line parameters.
Thanks
gg
A simple way would be to use the indexOf methods in String:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
Not sure what this has to do with event handling though :-P
Similar Messages
-
Help me about Searching for a Substring within a String
Hello everybody,
I have a problem like this:
Assume i type a sentence from keyboard: "I want to play football"
And computer will look for the word "football" to see if this word is in that sentence.
In this case, computer found it.
That is it ! Could anybody help me about this ?
Thank you very much in advance.
still_learnUse the String.indexOf() method:
String original = "I want to play football";
int result = original.indexOf("football");
if (result != -1)
System.out.println("computer found it");
If the word "football" is in the original String, the indexOf() method will return the index of the word. If it does not find the word "football", it will return a value of -1. The String API is full of useful methods.
fitz -
How to search for perticular substring in given string.
Hi, Can any one tell me how to search for perticular substring in given string.
example:
I have to search for CA in given Order type it may be CA10 or CA15. Please Do the needful.Hi Aniruddha,
check this...
Data var string,
var = 'India'.
search var for 'Ind'.
if sy-subrc = 0. " var having ind
Message 'Ind found' type 'I'.
else . "var not having ind
Message 'Ind not Found' type 'I'.
endif.
thanx
bgan. -
Looking for a substring within a string (regexp)
Hi folks,
I want to select a substring from a string
string:
21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY
or
21;0000;4145054;4;A;4 goldglamsnu XEOFX,198877,XEOFX YWY,1,YWY
I'm looking for the substring:
YWY,1,YWY
and try this SQL statement
SQL> select REGEXP_substr('21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY' ,',[^YWY]+[0-9]')
2 from dual;
REGEXP_
,117107
I don't know where my mistake is. Can anybody please help me?
Database Version 11G R2
Thanks,
ben
Edited by: ben512 on May 14, 2013 5:05 PMHi,
ben512 wrote:
Hi folks,
I want to select a substring from a string
string:
21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY
or
21;0000;4145054;4;A;4 goldglamsnu XEOFX,198877,XEOFX YWY,1,YWY
I'm looking for the substring:
YWY,1,YWYWhy do you want that substring. Do you always want the last 9 characters of the string?
If you're looking for a substring that starts with 'YWY', and then has any number (including 0) of commas, digits, and additional 'YWY' strings after it, then:
REGEXP_SUBSTR ( str
, 'YWY[,[:digit:]]*)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, maybe 5 or 10 rows), and also post the results you want from that data. Include examples of any special cases you need to handle (e.g., the target pattern is not found at all, or it is found at 2 different places in the string).
Explain, using specific examples, how you get those results from that data. Say what your business rules are.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
How to search for upper/lower case using string using JAVA!!!?
-I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears.
-I also have to use a JOptionPane.showMessageDialog() to tell the user how many upper and lower case e's were in the string.
-This will be repeated until the user types the word "Stop".
please help if you can
what i have so far:
[code]
public class Project0 {
public static void main(String[] args) {
String[] uppercase = {'E'};
String[] lowercase = {'e'};
String isOrIsNot, inputWord;
while (true) {
// This line asks the user for input by popping out a single window
// with text input
inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
if ( inputWord.equals("stop") )
System.exit(0);
// if the inputWord is contained within uppercase or
// lowercase return true
if (wordIsThere(inputWord, lowercase))
isOrIsNot = "Number of lower case e's: ";
if (wordIsThere(inputword, uppercase))
isOrIsNot = "number of upper case e's: ";
// Output to a JOptionPane window whether the word is on the list or not
JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
} //main
public static boolean wordIsThere(String findMe, String[] theList) {
for (int i=0; i<theList.length; ++i) {
if (findMe.equals(theList[i])) return true;
return false;
} // wordIsThere
} // class Lab4Program1
[/code]So what is your question? Do you get any errors? If so, post them. What doesn't work?
And crossposted: how to search for upper/lower case using string using JAVA!!!? -
after running through the forums i couldn't find anything that related to my question. so here it is.
to search for a substring, do i have to search for each individual character or is there an easier method...
for example:
String john,paul,mark,fabio,greg,park,rego
if i wanted to find all the strings with "ar" in them, would i have to search for a, and then r and check if the position of r is +1 a??
or is there an easier way??
thanks for your help!The documentation is your friend.
http://java.sun.com/j2se/1.4.1/docs/api/index.html
Look up what the method indexOf(String) of the class java.lang.String does. -
Search for a space within a text field
Hi All
I am trying to search for a sapce within a text field but sofar not being very successful. I have used:
FIND search_str
IN text_str
MATCH COUNT lv_mcnt
MATCH OFFSET lv_moff.
where search_str = TYPE c VALUE ' '.
I am looking a way of searching a character within the string using ABAP (like INSTRING in other languages). If you have similiar codes - Could you please post me a copy - ThanksHI
Check this..
DATA string7(30) TYPE c VALUE 'This is a little sentence.'.
WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
ULINE /1(26).
SEARCH string7 FOR 'X'.
WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',
sy-fdpos UNDER 'SY-FDPOS'.
SEARCH string7 FOR 'itt '.
WRITE: / 'itt ', sy-subrc UNDER 'SY-SUBRC',
sy-fdpos UNDER 'SY-FDPOS'.
SEARCH string7 FOR '.e .'.
WRITE: / '.e .', sy-subrc UNDER 'SY-SUBRC',
sy-fdpos UNDER 'SY-FDPOS'.
SEARCH string7 FOR '*e'.
WRITE: / '*e ', sy-subrc UNDER 'SY-SUBRC',
sy-fdpos UNDER 'SY-FDPOS'.
SEARCH string7 FOR 's*'.
WRITE: / 's* ', sy-subrc UNDER 'SY-SUBRC',
sy-fdpos UNDER 'SY-FDPOS'.
Thanks ,
Praveen -
How do I search for a word within a web page
I would like to be able to do a search for a pecific within the page currenly viewed in the browser. Is there a way to do that in Firefox?
Hi JossefPerl,
Searching on a page is actually really easy. You can just hit ''CTRL + F'' to use the search feature. You should take a look at the Knowledge Base article on [[Searching within a page]] for more information.
Hopefully this helps! -
Search for a word in a string.
Hello everybody,
Could anybody help me how to search for a word in a string ?
Example: I have a string as below:
String[] weather = {"snow", "rain", "sunny", "temperature", "storm", "freezing"};
And I have a sentence like this:
"Today is a sunny day"
I want to break this sentence to pickup the word "sunny" and search this word in String[] weather to see if they match. How could i do that?
Thank you very much. I really appreciate.
still_learn1 iterate through the strings in your array.
2. use String.indexOf(...) to test if the query string is present in the string -
Search for a song within a playlist in iTunes 11
I just want to know how do I search for a song within a playlist. I don't want to search the entire music library just one single playlist.
Got it. I have to deslect the Search Entire Library in the search field
-
Search for White space within strings
create table emp_dtl
(empname varchar2(23));
Insert into emp_dtl values ('WAYNE');
Insert into emp_dtl values ('JOSEPH KRUPP'); --------- has white space
Insert into emp_dtl values ('YING ZONG LEE'); --------- has white space
Insert into emp_dtl values ('COHEN');
Insert into emp_dtl values ('MARIE');How can i search for empnames which has White space in it? From other OTN threads, I gathered that this has something to do with
chr(32)But i don't know how to put this in LIKE operator.Hi,
SELECT *
FROM emp_dtl
WHERE REGEXP_LIKE (empname, '\s')
;will look for any kind of whitespace (including spaces, which are CHR (32)).
It may be more efficient to specifically list all the different whitespace characters, and see if the string changes when you remove all of them:
SELECT *
FROM emp_dtl
WHERE empname != TRANSLATE ( empname
, 'x ' || CHR (9) -- CHR (9) = <tab>
|| CHR (10) -- CHR (10) = <newline>
|| CHR (13) -- CHR (13) = <return>
, 'x'
;Edited by: Frank Kulash on Jul 12, 2010 8:47 AM -
How can I use SQL to search for a pattern within a field?
Hello, Frank, Solomon, ect
I am now faced with this particular scenario, I've got the SQL to search through a field to find text within the field, but I have to know what it is before it can look for it.
What I have to do is this:
Search through a field, for a pattern, and I won't know what the data is I am looking for. Can this be done in SQL?
For instance, Here is my SQL this far, I was helped allot in order to get to this point.
select table_name,
column_name,
:search_string search_string,
result
from (select column_name,
table_name,
'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
from cols
where table_name in ('TABLE1', 'TABLE2')),
xmltable (str columns result varchar2(10) path '.')
When you execute the above SQL, you have to pass in a value. What I really need is to alter the above SQL, to make it search for a pattern that exist's within the text of the field itself.
Like for instance, lets say the pattern I am looking for is this" xx-xxxxx-xxxx" and it's somewhere in a field.
I need to alter this SQL to take this pattern and search through all the schemas and tables to look for this pattern match.
Can be done?When you use something dynamically within a function or procedure, roles do not apply and privileges must be granted directly. So, you need to grant select on dba_tab_cols directly. If you want to do pattern matching then you should use regular expressions. The following example grants the proper privileges and uses regexp_instr to find all values containing the pattern xxx-xxxx-xxxx, where /S is used for any non-space character. I limited the tables in order to save time and output for the test, but you can eliminate that where clause.
SYS@orcl> CREATE USER test IDENTIFIED BY test
2 /
User created.
SYS@orcl> ALTER USER test QUOTA UNLIMITED ON USERS
2 /
User altered.
SYS@orcl> GRANT CREATE SESSION, CREATE TABLE TO test
2 /
Grant succeeded.
SYS@orcl> GRANT SELECT ON dba_tab_cols TO test
2 /
Grant succeeded.
SYS@orcl> CONNECT test/test
Connected.
TEST@orcl> SET LINESIZE 90
TEST@orcl> CREATE TABLE table1
2 (tab1_col1 VARCHAR2(60))
3 /
Table created.
TEST@orcl> INSERT ALL
2 INTO table1 (tab1_col1) VALUES ('xxx-xxxx-xxxx')
3 INTO table1 (tab1_col1) VALUES ('matching abc-defg-hijk data')
4 INTO table1 (tab1_col1) VALUES ('other data')
5 SELECT * FROM DUAL
6 /
3 rows created.
TEST@orcl> CREATE TABLE table2
2 (tab2_col2 VARCHAR2(30))
3 /
Table created.
TEST@orcl> INSERT ALL
2 INTO table2 (tab2_col2) VALUES ('this BCD-EFGH-IJKL too')
3 INTO table2 (tab2_col2) VALUES ('something else')
4 SELECT * FROM DUAL
5 /
2 rows created.
TEST@orcl> VAR search_string VARCHAR2(24)
TEST@orcl> EXEC :search_string := '\S\S\S-\S\S\S\S-\S\S\S\S'
PL/SQL procedure successfully completed.
TEST@orcl> COLUMN "Searchword" FORMAT A24
TEST@orcl> COLUMN "Table" FORMAT A6
TEST@orcl> COLUMN "Column/Value" FORMAT A50
TEST@orcl> SELECT DISTINCT SUBSTR (:search_string, 1, 24) "Searchword",
2 SUBSTR (table_name, 1, 14) "Table",
3 SUBSTR (t.column_value.getstringval (), 1, 50) "Column/Value"
4 FROM dba_tab_cols,
5 TABLE
6 (XMLSEQUENCE
7 (DBMS_XMLGEN.GETXMLTYPE
8 ( 'SELECT ' || column_name ||
9 ' FROM ' || table_name ||
10 ' WHERE REGEXP_INSTR
11 (UPPER (' || column_name || '),''' ||
12 UPPER (:search_string) || ''') > 0'
13 ).extract ('ROWSET/ROW/*'))) t
14 WHERE table_name IN ('TABLE1', 'TABLE2')
15 ORDER BY "Table"
16 /
Searchword Table Column/Value
\S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>matching abc-defg-hijk data</TAB1_COL1>
\S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>xxx-xxxx-xxxx</TAB1_COL1>
\S\S\S-\S\S\S\S-\S\S\S\S TABLE2 <TAB2_COL2>this BCD-EFGH-IJKL too</TAB2_COL2>
3 rows selected. -
Search for certain Characters within set of Characters - in a field
Hello -
I know a search can be made within a field for a word, but I am not to sure, or I don't know how to accomplish this...To do a search in a field for certain characters within a larger set of charcters.
For example: I would search, in the Call Description field, for DXXXX within CA0001DXXXXYYY or search for LXXXX within CA0001LXXXXYYY, the X is numeric characters and the Y's are Alpha characters. Can crystal accomplish this....
Thanks for your gracious help....
G.Like I said earlier, this code:
If instr({database_field}, 'DXXXX') > 0 then "String Found" else "Not Found"
cannot be used in a Record Selection formula.
The following code can be used in the Record Selection formula:
Instr({database field}, "string") > 0
If you wish to search for 'D4444' in the field and return records where a match is found, you would use:
Instr({database field}, "D4444") > 0
-Abhilash -
Searching for percent character (%) in a string
Hi All,
A strange request from one of our developers that I have not come across before.
Is there a way to search for a percent character (%) in a string and also use the wildcard special character (%)?
i.e. to return all values with a percent character (%)
e.g. select column1 from table1 where column1 like '%%';
When I do this all records are returned.
Regards!!or use an INSTR function.If INSTR comes, can REGEXP be far behind ? - Ode to the Warren Tolentino... ;)
test@ORA10G>
test@ORA10G> @ver1
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
test@ORA10G>
test@ORA10G> with t as
2 (select 'the percentage (%) determines the final results' remarks from dual union all
3 select 'otherwise non at all' remarks from dual)
4 select * from t
5 where regexp_like (remarks,'%');
REMARKS
the percentage (%) determines the final results
test@ORA10G>
test@ORA10G> with t as
2 (select 'the percentage (%) determines the final results' remarks from dual union all
3 select 'otherwise non at all' remarks from dual)
4 select * from t
5 where regexp_instr (remarks,'%') > 0;
REMARKS
the percentage (%) determines the final results
test@ORA10G>
test@ORA10G>pratz -
I want to Search for a file within a directory
how can i access a directory and search for a folder name in that directory
Hi,
SQL> set serveroutput on
SQL>
SQL> Declare
2 l_conn UTL_TCP.connection;
3 l_list ftp.t_string_table;
4 Begin
5 DBMS_OUTPUT.disable;
6
7 l_conn := ftp.login( '172.21.15.15'
8 , '21'
9 , 'test'
10 , 'test123' );
11
12 ftp.list( p_conn => l_conn
13 , p_dir => ''
14 , p_list => l_list );
15
16 ftp.logout(l_conn);
17
18 utl_tcp.close_all_connections;
19
20 DBMS_OUTPUT.Enable;
21
22 If l_list.Count > 0 Then
23 For i IN 3 .. l_list.Last Loop
24 DBMS_OUTPUT.put_line(Trim(substr(l_list(i),instr(l_list(i),' ',-1))));
25 End Loop;
26 End If;
27 End;
28 /
files1
files10
files11
files2
files3
files4
files5
files6
files7
files8
files9
PL/SQL procedure successfully completedhttp://www.oracle-base.com/articles/misc/FTPFromPLSQL.php
http://www.oracle-base.com/dba/miscellaneous/ftp.pks
http://www.oracle-base.com/dba/miscellaneous/ftp.pkb
Or Chris Poole's XUTL_FTP package:
http://www.chrispoole.co.uk/apps/xutlftp.htm
or with DBMS_BACKUP_RESTORE
SQL> -- How to Install
SQL> -- .../RDBMS/ADMIN/dbmsbkrs.sql
SQL> -- .../RDBMS/ADMIN/prvtbkrs.plb
SQL> -- .../RDBMS/ADMIN/catproc.sql
SQL>
SQL> Set Serveroutput on;
SQL> Create or replace directory DIR_TEMP as 'c:\temp';
Directory created
SQL> Create OR Replace Procedure list_directory(directory Varchar2) Is
2 ns Varchar2(1024);
3 v_directory Varchar2(1024);
4 Begin
5 v_directory := directory;
6 DBMS_BACKUP_RESTORE.SEARCHFILES( v_directory
7 , ns );
8 For each_file IN (SELECT fname_krbmsft As Name
9 FROM x$krbmsft) Loop
10 DBMS_OUTPUT.PUT_LINE(each_file.Name);
11 End Loop;
12 End;
13 /
Procedure created
SQL> begin
2 list_directory('c:\temp');
3 end;
4 /
C:\Temp\prvtbcnf.plb
C:\Temp\something.txt
PL/SQL procedure successfully completedRegards,
Christian Balz
Maybe you are looking for
-
I have saved some of the related tabs in a common sub folder in the bookmarks list and whenever i have to open this tabs always i have to open them individually coz the 'open all in new tabs' option is not available for subfolder, so is there any com
-
My 6th generation iPod nano won
I'm unable to use the "shuffle" feature on my 6th generation iPod nano. Any thoughts?
-
How can I swap my photos and the apps I have paid for, from my iphone 4s to iphone 5?
I am having trouble swapping my photos and videos along with my paid apps to my new phone I dont have access to a computer and cant let my old phone go until I have all the pictures. Also have a few apps i have paid for. Please can someone advise me
-
Hi Everyone Quick question... I'm looking to purchase a third mac just for the purpose of capturing video as well as burning DVDs. Capturing will be to external firewire drives (SD Video Only). I'm using FCP 4 and DVD Studio 2. What should my minimal
-
Cant delete songs or playlists
everytime i click on a song and press the delete button, itunes quits unexpectedly. I always relaunch it and no matter how much ways i try to delete a song or playlist, itunes always quits. the same goes for imovie and ical. i just recently installed