How to find a string inside another String variable
Hi,
I need to find whether a string is available in a String of varying length.
i.e., i want to know string "access" is available in a String variable( may have values like "microsoft access 2000 bla bla bla .." or "bla bla access microsoft").
so, i dont know the starting point of the word 'access' in the String variable.
Pls help me in doing this.
Thanks in advance,
Rao
Check the API documentation for this method:
"int indexOf(String str)
Returns the index within this string of the first occurrence of the specified substring."
Similar Messages
-
Find occurences of a string inside another string
How can I loop through String text for occurences of String lineSeparator, and replace each occurence with String lineShift?
String lineSeparator = "<line_separator/>";
String lineShift = "\n";
String text = "This<line_separator/>is<line_separator/>a<line_separator/>test<line_separator/>";Do I have to use Patterns or something?String lineSeparator = "<line_separator/>";
String lineShift = "\n";
String text = "This<line_separator/>is<line_separator/>a<line_separator/>test<line_separator/>";
String modified = text.replaceAll(lineSeparator, lineShift);
System.out.println(modified); -
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. -
I need to append a string to another string
I'm working with some inherited code, I'm a Colf Fusion
novice myself, and I'm trying to make this order form display the
correct data. The problem is a lot of data in the database is
missing. Description in the QStockDB query can contain a lot of
stuff. For our full color work the text "4/0", "4/BLACK", and "4/4"
are consistent so I'm changing the newitem (I know, not very
descriptive but it's not my code) to CMYK Printing.
<cfif #QStockDB.description# contains "4/0"><cfset
newitem = "CMYK Printing"></cfif>
<cfif #QStockDB.description# contains
"4/4/BLACK"><cfset newitem = "CMYK Printing"></cfif>
<cfif #QStockDB.description# contains "4/4"><cfset
newitem = "CMYK Printing"></cfif>
I want to then go back through description and compare it
more to add more description. For instance with this:
<cfif #QStockDB.description# contains "12 pt"><cfset
newitem = newitem + " - BC"></cfif>
I know that the job is a business card. So I want to append
the newitem variable with " - BC". Likewise:
<cfif #QStockDB.description# contains
"catalog"><cfset newitem = newitem + " - Catalog
Sheets"></cfif>
displays CMYK Printing - Catalog Sheets. Or, it should... or,
more precisely, I want it to. :)
How do I append a string to another string?+ is the addiion operator and works with numbers. Because
your string is a ...well, string... you need to use an ampersand.
Thus, instead of:
<cfif #QStockDB.description# contains
"catalog"><cfset newitem = newitem + " - Catalog
Sheets"></cfif>
Use...
<cfif #QStockDB.description# contains
"catalog"><cfset newitem = newitem & " - Catalog
Sheets"></cfif>
<cfoutput>#newitem#</cfoutput>
At least I think that will work - haven't tested it
though. -
Replace a string with another string in a file
I have to replace a string with another string. Say for example in a html file it got a line like,
<a href="##"></a>
now i want to replace this ## with the full derived path like
"c;\\sample folder\\sample subfolder\\samplefile.html"
can someone help me to do this?
pls tell me from the file opening till closing the file.I have to replace a string with another string. Say
for example in a html file it got a line like,
<a href="##"></a>
now i want to replace this ## with the full derived
path like
"c;\\sample folder\\samplesubfolder\\samplefile.html"
can someone help me to do this?
pls tell me from the file opening till closing the
file.
public class Buckel {
final static String CONST = "c:\\sample folder\\samplesubfolder\\samplefile.html";
public Buckel() {
public static void main ( String[] argv ) throws Exception {
int idx = 0;
String in = "<a href=\"##\"></a>", // We'll imagine this just gets here somehow. If it's on the i/p file then take the '\' out B4 and aft the '##'.
out = "";
idx = in.indexOf( "##" );
if ( idx > 0 ) {
out = in.substring( 0, idx ) + CONST + in.substring( idx+=2, in.length() );
System.out.println( out );
} -
How do I find one string inside another?
I've been looking through the documentation, but have yet to find what I need. While I keep looking, maybe someone here has a good idea...
I have a TreeSet of Strings ts = { "foo", "bar", "green car" }, and another String s = "this is my new green car". I need to identify which Strings from ts are present inside s.
Current idea:
String s = "this is my new green car";
boolean bFoundOne = false;
Iterator iter = ts.iterator();
while(iter.hasNext() && !bFoundOne)
bFoundOne = Contains(s, iter.next());
boolean Contains(String sMaster, sCompare)
// what goes here???Ah, yes! That's it! It would have to be something so simple... I was reading about java.text.collate and things like this. ;)
-
How to find out if a long String has a "subString" twice or more.
I need to find out if a long String has the same number twice or more.
I need to look matches for numbers running from 000, 001....999 and if a number is found twice or more, return that number and lines there were found.
example String:
-;000 ; 1 ; 2006-12-11 ; -; job;
x;001 ; 2 ; 2006-12-11 ; 2006-12-12; do this
-;002 ; 3 ; 2006-12-11 ; -; work
-;003 ; 0 ; 2006-12-11 ; -; some
-;004 ; 2 ; 2006-12-11 ; -; thing
x;005 ; 1 ; 2006-12-11 ; 2006-12-11; reads
-;003 ; 0 ; 2006-12-11 ; -; here
Should return from example String:
003 at lines 4 and 7
Any ideas?So there are newlines in the String?
You could use a StringTokenizer to break the String into lines, then searching on each line if it contains any of the search strings. (You need to clarify if a line can contain more than one search string).
Probably you should use a Map<String, Integer> to record the searchcounts.
Or an int[] Array if you are really sure that the Strings you search for really are numbers.
Another option is to use:
LineNumberReader lnr = new LineNumberReader(new StringReader(searchString));This will save you from explicitly having to take care for the line number.
In any case your example looks like the individual lines are semicolon separated fields and the numbers you search for always are in column two.
So after breaking up the original String in lines, you could use another StringTokenizer to break up the line in fields. -
How can I substitute a string with another string in a file
I have a file. I have a substitute a keyword with another string in all the occurences of a file. How can I do this?
I'm gonna give you the benifit of the doubt and assume you didn't mean to double post your question.
As to substitute a keyword with a string one way is to read in the file and run it through a StreamTokenizer class to break it into words. Pull one word at a time, check it, and stick it into a StringBuffer. Once your done with the file overwrite it with what is in the StringBuffer.
Another way might be to use the RandomAccessFile class, but I'm not really familiar with that because I hardly ever use it. -
How to register one MBean inside another MBean
Hi All,
When i try to register one MBean(DynMBean1) inside another(DynMBean2) by passing object name of this MBean as attribute to the other MBean,iam getting the following error:
Following shows the adapter interface
List of MBean attributes:
Name Type Access Value
DynBean2 java.lang.ObjectName RW Type Not Supported: [ [DynBean2:bean=sample]
name java.lang.String RW
if the above code works properly,in the ''value' column there should be ''view' button and only [DynBean2:bean=sample]' should be present in the value column.Also,if we click on Can any predict what the problem is......?
Regards
Ravi
Mail Me:[email protected]I don't understand what you mean by register a bean inside another bean.
-
How to put an MSO inside another MSO
Hello all!
An interesting question came up in the following post by Folobo:
http://forums.adobe.com/message/4572897#4572897
"Is it possible to use a slideshow embedded in a big overlay slideshow?"
I'd like to rephrase this question:
"Is it possible to put a MultiStateObject (MSO) inside another MultiStateObject?"
And further: if the answer is "yes", could we put that to use with the DPS?
@Folobo – this is an interesting question. A quick test is showing that you cannot do it in the UI (correct me if I'm wrong).
Let's try it this way:
If you have two objects:
1. an MSO #1 (with two rectangles, rectangle #1, rectangle #2)
2. Another rectangle on the page: rectangle #3
Now select the two objects and make an MSO out of it (using the "Object States" panel).
You would think, now I get an MSO with two states, state 1 with rectangle #3 together with state 2 with MSO #1.
But not so:
Result: One new MSO with three states (rectangle #1, rectangle #2, rectangle #3)
Hm. I don't give up on that. Let's try it another way:
Could we select at least two objects inside a state of an MSO and make that a new MSO?
Sure, We could select two objects inside a state, but since we are *inside* an MSO the "Object States" panel does not show the possibility to make a new MSO. You can only add states or add objects to states…
Frustrating. End of story? Maybe…
Be forewarned. The following is highly experimental!
Let's try it by scripting (ExtendScript/JavaScript).
The scripting reference is showing that an MSO "MultiStateObject" object has an add()-method. And further on, that add()-method could be applied to:
Document
Spread
MasterSpread
Page
Layer
pageItem
And that is the key to a possible solution. We could add a new MSO to a "pageItem" object.
A simple rectangle should be qualify for a "pageItem" object; and that, of course, could reside in a state of an MSO.
So, we could add a new MSO to a rectangle inside of a MSO!
How can we access a rectangle inside a MSO? Easy: We could select it and work with that selection.
So let's do that: select the rectangle in the first state of an MSO and run this one-line-script (be sure you did select the rectangle and not the MSO or one of its states:
app.selection[0].multiStateObjects.add();
We now have an MSO inside another MSO!
Explanation:
A "generic MSO" was added with the add()-function to a selection (the container object: in our case the selected rectangle).
The "generic MSO" is a two state MSO consisting of one rectangle in each state of a very small size (10px x 10px).
At first it is invisible, because it is very likely that it is positioned outside the geometric bounds of its container object (the rectangle).
But we can customize this!
Go to the layers palette and select the new MSO, move it inside the geometric bounds of its container object, readjust its size, add states as you wish, populate the states with images, and other objects etc.pp.
So, what can we do with an MSO inside another MSO? (As I already said, this is highly experimental.)
My experiments with that are very fresh. I did not try a lot. But it seems that we could at least autoplay this MSO.
I have to test more thoroughly what is possible and what will work with buttons etc.pp…
I really like to hear from you what you will find out and if you can put it to any use.
Uwe
Message was edited by: Laubender@Mobly – in case it did not work out for you, here some screen grabs for the different steps:
1. Select an MSO:
2. Select a "graphic frame" inside the MSO; in this case a "<square>"; you can see the big blue dot in the Layers panel behind the generic name "<square>":
3. Open the Scripts Panel and select the script:
4. Run the script by double-clicking the script; the generic name of your selected object has changed to "graphic frame", but trust me, it's still a square…
5. Click the "Ok" button of the message and InDesign will select the new MSO ("Multi-state 2") as you can see here. It has two states with one rectangle each, fill and stroke is "None":
And: you can see that this new MSO is nested inside the MSO ("Multi-state 1").
What you do with that construct is up to you:
6. Color the "<square>" of state 1 of "Multi-state 2":
7. Resize and change position of "Multi-state 2":
8. But remember: "Multi-state 2" is nested in the graphic frame you selected before running the script:
I hope you get the picture now…
Uwe -
Check if a string contains another string
can anybody help?
String st="DC";
how can i check if another string contains "DC" or not?How bout
if(someString.indexOf(st) != -1) {
//someString contains st at some point
} -
Copyieng some charecters from string to another string
hi all,
its urgent.
there r two strings
A = 'IEQ0100'.
AA = ' '.
and i want to copy only last 4 charecters from String A to String AA.
could u please help me
thx in advance..........
Sunill =strlen(a).
d = l - 4.
aa1(4) = ad(4).
REPORT zex35 .
DATA : a(7) VALUE 'IEQ0100',
aa(7) VALUE ' '.
DATA : l TYPE i,
d TYPE i.
l = strlen( a ).
d = l - 4.
aa1(4) = ad(4).
WRITE : / aa.
If u dont want first character space in aa then change the below statement
aa1(4) = ad(4).
to
aa0(4) = ad(4)
or
aa = a+d(4). -
How to find out the index in string.
Hello Experts,
I have a requirement in which i have to find out the index of the last space before the 50th position in a string.
is there any way other than spliting the string.
e.g. if string is - 'aaaa aaaa aaa........ aaa aaa'(length is more than 50)
i want the last space before 50th char.because i want to split the string before last word withing 50 th character
please help.
Thanks,
ShwetaHi Shweta,
You can build up the logic from this below program.
data: line(75) value 'abcdefghijk lmnopqrstuvwxyz zyxwvutsrqponml kjihgfedc ba',
n_line(50),
off type i,
val1(50),
val2(50).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = line(50)
LANG = ' '
IMPORTING
RSTRING = n_line
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SPLIT n_line at space into val1 val2.
off = strlen( val1 ).
off = 50 - off.
write: 'The index of the last space before the 50th position is at ', off.
Hope this may help you.
Regards,
Smart Varghese -
How to find files starting by a string?
Hello.
I need a way to read all files in a directory whose names start with a string in order to update a field in a table. I wonder if there is a way of doing that in pl/sql.
As this procedure will be called in a shell script I guess I could do that in shell script but I don't know how to do that.
Can someone help me?
Thanks anyone.Yes Kamal, as an old Unix user, I don't like spaces within names, and normally I don't use them :-)
but the problem can be solved :
$ ls -l va*
-rw-r--r-- 1 oracle oinstall 240813 27 ago 10:39 valind.sql
-rw-r--r-- 1 oracle oinstall 283 18 feb 2005 val.sql
-rw-r--r-- 1 oracle oinstall 62 5 dic 18:52 var 123.txt
-rw-r--r-- 1 oracle oinstall 154 5 set 17:16 var1.sql
$ cat disp.sh
ls va* | while read FILE
do
sqlplus -s scott/tiger << EOF
set serveroutput on
exec disp_file('$FILE');
exit
EOF
done
$ ./disp.sh
valind.sql
PL/SQL procedure successfully completed.
val.sql
PL/SQL procedure successfully completed.
var 123.txt
PL/SQL procedure successfully completed.
var1.sql
PL/SQL procedure successfully completed.
$ -
How to replace part of a String with another String :s ?
Got a String
" Team_1/Team_2/Team_3/ "
And I want to be able to rename part of the string (they are seperated by '/'), for example I want to rename "Team_3" to "Team C", and "Team_1" to "Team A" while retaining the '/' character how would I do this?
I have tried using String.replace(oldValue, newValue); but this doesnt work, any ideas?What do you mean that it doesn't work? You do know that the method returns the modified string? The actual string that you invoke the method on is not altered.
/Kaj
Maybe you are looking for
-
In limbo between Leopard and Snow Leopard - stupidly didn't back up
I've got an old-school black MacBook, about four years old now. I never cared enough to upgrade it to Snow Leopard, but now I want Lion. So, I borrowed my parents' five-license Snow Leopard install disc and started off on the journey to upgrade to Sn
-
Database connectivity in labview?
when I select the OLE DB provider is "microsoft OLE DB provider for ODBC Drivers",I can write to database,but I can't read from database using data connectivity toolkit? i use the SQL language SELECT * FROM motor WHERE serial="aaa" the error is : "er
-
Is it possible to make a shortcut key to would do the "paste" function?
The hard part is that I want to paste in another program, like if I open a notepad, I can just click a botton in a java program, a string would have been saved in the clipboard, and then just press a shortcut key would paste the string on the notepad
-
Hello, I own an iPod Touch, I transfer the photos over to my computer in the folder on my computer the pictures are sorted the way I want, but once the transfer is complete, photos are categorized differently in the Ipod .. .! He decided to classify
-
Hi, My company has a large investment in CS3. We have .Net application that uses InDesign scripts. If we upgrade to the latest version if InDesign, will our scripts break? Thank you, Steve