How to find a String in a Vector???
Hi!!
Thanks in advance for read this post. I have a little problem... please help me.
I need to find if a String exists or not in a Vector. The vector is a list of results from a database. Here goes my code:
<html>
... html code ...
<%
int IdClass = Integer.parseInt(request.getParameter("IdClass"));
int module = Integer.parseInt(request.getParameter("module");
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
int oError = -1;
String oMessage = null;
List Functions = new Vector();
CallableStatement cs = null;
try{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DBConnection.GetConnection(DBConnection.DSN);
if (conn != null) {
cs = conn.prepareCall ("begin procedure(?,?,?,?); end;");
cs.setInt(1,IdClass);
cs.registerOutParameter(2,Types.INTEGER);
cs.registerOutParameter(3,Types.VARCHAR);
cs.registerOutParameter(4,OracleTypes.CURSOR);
cs.execute();
rs = (ResultSet)cs.getObject(4);
oError = cs.getInt(2);
oMessage = cs.getString(3);
if (oError == 0) {
while (rs.next()) {
Functions.add(rs.getString(1));
session.setAttribute("sessionFunctions", Functions);
out.println("<script>document.location.href=\"Ok.jsp\";</script>");
else {
String message = null;
message = "Error "+oError+": "+oMessage;
out.println("<script>document.location.href=\"NO.jsp\";</script>");
cs.close();
if (conn != null) {
conn.close();
%>
... html code...
</html>
That code generates a Vector that contains this:
[1, 2, 3, 6, 7, 8, 15, 28, 35, 41, 58, 65, 66, 68, 71, 74]
In the Ok.jsp page, i have a String like this:
String access = "2,7,14,15,28";
First, i need to get the values of the sessionFunctions.
String X = (String)session.getAttribute("sessionFunctions");
I need to know if each number (2,7,14...) exists in the vector. For example, in this case, the follow numbers exists: 2, 7, 15, 28.
So, if the number exists in the Vector, i will generate some HTML code. If not, i will generate a different HTML Code.
if (String exists in Vector = 1) {
out.println("Yes!!!");
else {
out.println("No...");
Can somebody help me? I`ve read a lot of examples, a lot of posts in this forum, i`ve look a lot of files of another project in my company, but i can�t find how to do this...
Thanks in advance.
Rapeteiro.
If you are putting a Vector in a session, you should be able to get it back as a Vector. Try this:
// retrieve Functions Vector from session
Vector userProfile = (Vector) session.getAttribute("sessionFunctions");
String access = "2,7,14,15,28";
// prepare a Vector from this string
Vector accessVector = new Vector();
StringTokenizer acsTokenizer = new StringTokenizer(access, ",");
while(acsTokenizer.hasMoreTokens ())
accessVector.addElement (acsTokenizer.nextElement ());
// check for each function in string against userProfile Vector
for(int f=0;f<accessVector.size ();f++)
String function = (String)accessVector.elementAt (f);
if(userProfile.contains (function)
%>User has access to this function<%
else
%>User does not have access to this function<%
Hope this helps!
-Mak
Similar Messages
-
How to find a string in SAP code
Hello,
Does anyone here know how I can find a string inside the SAP code efficiently? I tried finding a custom table name using the Where-used list feature but the results doesn't show the complete/correct results. It missed some user exits where the table name was also used.
Please helpHello Jimmy,
You can try what Krishna has said there is one more way that is
goto trxn SE12,
enter Z* in the table name field,
it will give a popup box with all the Ztables found in your system...you can find your table maybe it is a little tedious job
Sravani -
How to find a string inside Excel table
Hi,
I am trying to find a string inside Excel table, and it does not work. Please see attached figure. I use the find Invoke Node and do not get anthing.
Please help
Attachments:
find_excel.JPG 21 KBSee attached files.
Thanks,
David
Attachments:
Excel_table.xls 15 KB
Read_XL.vi 42 KB -
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,
RaoCheck the API documentation for this method:
"int indexOf(String str)
Returns the index within this string of the first occurrence of the specified substring." -
How to find a string in all directories/folders
Good Day,
I need to search for a word through out all the directories .Is there any command that which I can type to search for a string in all the directories,folders and sub folders at one time.
Thanks in advance.
Regards,
Gopi.CH
Edited by: 915796 on 10-Jun-2012 19:18Use the find command if you are looking for a specific file or directory name. The following example will find only filenames (type f) that contain the word "sample", but exclude the results found in /usr and /u01:
# find / -type f -name "*sample*" | egrep -v "/u01|/usr"
/home/oracle/snippets/parse2.sample
/home/oracle/snippets/parse3.sample
/root/sample.bin.dc
/root/sample2.bin
/root/sample.bin
/root/sample.des
/root/sample.out
/etc/gdm/PostLogin/Default.sample
/proc/sys/kernel/perf_event_max_sample_rateUse the grep command to search for content. For example:
# grep -r "Dude" /home
/home/oracle/snippets/sched_stop_dist.sh:# Author : Dude
/home/oracle/snippets/healthcheck.sh:# Author: Dude -
How to find a string in a text file
i'll have a text file in the following format and from this this type of file i've to get source URL i.e in the following file http://www.consolidatorshopper.com/patheo/Mall/prices.asp
and also i've to get POSTdata querystring i.e in the following file from cosolidateorname...... to &conid6=7
hope you people understood my problem
i'll be very thankful if u people help me
BEGIN HEADER
source:http://www.consolidatorshopper.com/patheo/Mall/prices.asp
POSTdata:consolidatorname=IF&AgentID=37344&SubAgentID=31030&LoginType=SUBAGNT&LoginConfirm=yes&ManageAccount=&CustomAccount=6&PALPowerSearch=2&ShowConsolidatorsOnPricesPage=0&PALHomePage=http://www.consolidatorshopper.com&PMarkup=0&PALLoginText=<B>Specific%20Consolidator%20Search:</B><BR>%20Click%20on%20the%20desired%20region%20on%20the%20map.<BR><BR><B>Power%20Search:</B><BR>To%20search%20all%20consolidators%20simultaneously%20click%20on%20the%20button%20below.%20However,%20not%20all%20consolidators%20currently%20participate%20in%20the%20Power%20Search.&PALrelativeLoginURL=&PALrelativeBookingURL=&[email protected]&SiteID=3&MallOwnerMarkupFlat=&conidselected=16&powersearch=2&iscontinentselected=1&Continent=USDomestic&Source=1&CRSName=AP&[email protected]&ConsolidatorURL=http://www.patheo.com&ConsolidatorPhone=714-677-0929&ConsolidatorFax=714-908-7110&ConsolidatorFullName=Patheo&noofconselected=7&amadeusconidstring=&flagamadeus=1&PowerSearchConsolidatorstring=&PublishedCRS=&APPseudoCity=&SBPseudoCity=&AMLogin=&assword=&AMCorpID=&AMCatNo=&ConsolidatorFares=1&PublishedFares=0&PublishedConsolidator=0&PreferencedConsolidator=&Arciata=&dep_from=MIA&dep_to=LON&ret_from=LON&ret_to=MIA&dep_month=08&dep_day=08&dep_year=2003&dep_weekday=Thu&txtLengthOfStay=7&ret_month=08&ret_day=15&ret_year=2003&ret_weekday=Thu&dep_time=12P&ret_time=12P&triptype=RoundTrip&simpleclass=Economy&srchAirline=&adultno=1&childno=0&infantno=0&conid0=11&conid1=97&conid2=1&conid3=86&conid4=5&conid5=94&conid6=7
BEGIN INFORMATION
TimeStamp:datetime:date()
BEGIN ACTION
startafter:<tr valign=middle bordercolor=#ffffff>endat:</table>
pattern:<font face='Arial, Helvetica, sans-serif' size='2'>[^<]*
$1:SYMBOL:TEXT
$2:INDEX:TEXT
$3:CLOSING:FLOAT
$4:CHANGE:FLOAT:StripHTMLTags()
$5:CHANGEPCT:FLOAT:StripHTMLTags()
BEGIN DOHi, this is my fourth post to forum.java.sun.com and my final one for the day, so I can allow feedback to emerge on my compliance or lack thereof with the conventions of the board.
Fortunately, I have picked up the skill of telepathy and so am able to answer your question. :)
In your processLine(String line) method or equivalent, you can do something like this:
if (line.indexOf("source:") == 0) {
source = line.substring(6, line.length());
} else if (line.indexOf("POSTdata:") == 0) {
postdata = line.substring(9, line.length()); -
How to find a string from a set of records?
I am having a stored procedure which is used for creating a crystal report. When I run the stored procedure sometimes it gives more than one row of data. I want to check if a particular string exists in any row of a particular column. To make it clear let me give an example
When I run the query I get the below columns
Part Part type
A001 Blanket
A002 Blanket
A003 Toys
What I want to check is if Toys is appearing in any of the row in a formula in crystal reports.
Thanks
Sreejith JHi,
If you want to check a particular sub string or part of a string within a string, you can try this:
if instr(<database column>, <String to be searched>) = 1 then true
So, your formula output will be true if the <string to be searched> is part of your <database field>.
Thanks,
Raghavendra -
How to find all solutions for reordering of vector
hello everyone
-I have problem in finding all possible solutions for reordering of vector.
-I have vector named (vect_temp) and I want to find all possible reordering of this vector.
-I have function named Min_diff(vect_temp,next_point) works as follows : I should gave it an element (next_point) in the vector (vect_temp) and it must generate the vector (vect_diff) that contains all possible elements next elements.
-The function nex_min(vect_temp,next_point) works as follows : I should gave it an element (next_point) in the vector (vect_temp) and it must generate the vector (vect_min) that contains all possible elements next elements.
-reordering critriea:
-Min_diff(vect_temp,next_point) and nex_min(vect_temp,next_point) and (next_point) in this first iteration is equal to any selected element in the (vect_temp). after calling the functions, if element in the (vect_diff) is equal to the element in ( vect_min) then add this element into the ordered set [ vec_ordering] and call functions Min_diff(vect_temp,next_point) and nex_min(vect_temp,next_point) again , next_point now is the equal to the element that we have been added in the previous step into the ordered set [ vec_ordering] and repeat this process until all elements in (vect_temp) are ordered according to this criteria.
- I'm able to do reordering according to the cirtira above and find one solution. but the problem is that if (vect_diff) contains many elements that equal to many elements in ( vect_min), in this case I need to do reordering for the first equal element and this will be one solution and then find reordering for the next equal element and so on.
let's consider this example:
- let (vect_temp) contains element [5,9,7,3,1]
- for the firs iteration let the next_point equal to 7
- after calling function Min_diff(vect_temp,next_point), then (vect_diff) will contain [ 5,9,3]
- after calling function nex_min(vect_temp,next_point), then ( vect_min) will contain [ 5,9]
so for now (vect_diff) and ( vect_min) will have two equal elements.
- the first solution must be that fist take the first equal element and do reordering such that ordered set [ vec_ordering] will equal to [7,5] then call functions Min_diff(vect_temp,next_point), and nex_min(vect_temp,next_point) again. the( next_point) in this iteration is qual to 5, these funtions will find next elements, let's consider that (vect_diff) and ( vect_min) will have equal element [3] then add this element to the ordered set [ vec_ordering] and repeat calling functions util all elments in (vect_temp) are added to the ordered set [ vec_ordering]. This will be one solution. now the second solution will be is to take second equal elment [9] instead of [5] and continue calling functions and finding ordered list.
so that each time vect_diff and vect_min will have many equal elements, then do reordering for first equal element this is one solution and then do reordering for the second equal element and so on.
-my code that can only find one solution that takes only first equal element in (vect_diff) and ( vect_min) and continue ordering is below
for (int y = 0; y < vect_temp.size(); y++) {
Min_diff(vect_temp);
nex_min(vect_temp, next_point);
for (int i = 0; i < vect_diff.size(); i++) {
String element_min = vect_diff.get(i).toString();
if (vect_min.contains(element_min)) {
vec_ordering.add(element_min);
_2nd_min_element = element_min;
vec_temp.removeElement(next_point);
next_point = _2nd_min_element;
i = vect_diff.size();
}// end if condition
} // end for (i)loop
}// end for (y) loop
I hope that someone can answer me how to find all posssible reordering set it is urgent pleasssssseDarrylBurke wrote:
Two months on and you still haven't done your own homework?
[http://forums.sun.com/thread.jspa?threadID=5423090]
dbWell, nobody has given the answer yet, so how can (s)he? -
How to find the number of occurence of a string
String str="The AR tech seeks experienced candidates in java,jsp. The candidates should have atleast 1 year of experience in the specified skills.";
here i need to find the number of occurence of the string "experience".
how to find it out?String str="The AR tech seeks experienced candidates in java,jsp. The candidates should have atleast 1 year of experience in the specified skills.";
String findStr = "experience";
int count = 0;
int index = 0;
while(index != -1) {
index = str.indexOf(findStr, (count == 0 ? 0 : index + findStr.length()));
if(index != -1) {
count++; -
How to find the number of occurance of a string in text field of Infopath form?
Hi All,
In Infopath text field, How to find the number of occurrence of a particular string in that field?
Thanks in advance!You can check to see if it contains a string once by using the contains function, but there isn't a very clean way to do what you want. If you wanted to guess at the maximum number of occurrences, then you could:
Box A has your initial. Set Box B to do a concat of string-before and string-after of Box A where it copies Box A minus the string we're looking for. Then we have Box C that does the same thing to Box B. Repeat as many times as you see necessary.
Example:
String: "1"
Box A - "123451234512345"
Box B - "23451234512345"
Box C - "2345234512345"
Box D - "234523452345"
etc.
We then have a field that has nested ifs looking backwards from Z -> A looking for a non-blank. Based on that, we return the number of occurrences. Again, this isn't clean, but it will work if you think there's a predefinable maximum.
Andy Wessendorf SharePoint Developer II | Rackspace [email protected] -
How to find out no of lines in String
Hi all,
How to find no of lines in a multi lined String.
For example.
String str = "hjkhjkhjhjhkhlk\nfjdhfjhdjfhjdhfj\nfdhfjdhjfhdj\ndfjdkjffjdfjk\nfdffdh";
Here there are 5 lines because there are "\n".
I am not able to substring with "\n".
Any idea please?javadocs StringTokenizer
StringTokenizer(String str, String delim)
Constructs a string tokenizer for the specified string.
Method Summary
int countTokens() -
How to find out if there are repeated characters in a string
hey guys
well i kinda have a little problem figuring out how to find out
if there are repeated characters in a string.
if anyone can help, would appreciate it.
thanks
milosTry using the StringTokenizer class. if u already know which character to trace. this could do the job.
eg. String str = "here and there its everywhere";
StringTokenizer st = new StringTokenizer(str, "e");
int rep = st.countTokens(); -
How to find out what are the functions supported by string class
Hi,
Can any one let me know how to find what are all the functions supported by the string class in standard(STL) library on solaris.
Regards,
Vignesh1. Any C++ textbook that covers the Standard Library will tell you about the standard string class. A good tutorial and reference for the entire Standard Library is "The C++ Standard Library" by Nicolai Josuttis, published by Addison Wesley.
2. WIth Sun C++, the command
man -s3C++ basic_string
provides documentation for the default libCstd version of the Standard Library.
3. You could look at the <string> header itself. I don't recommend that approach. -
How to find number of characters in a character string
Hi,
Can anyone please tell me about how to find the number of characters in a character string type variable.
Reagards,
Sivahi,
Use STRLEN for Calculating String Length..
Assign it to integer variable for Further Use.Suppse u need to find string length for "hai".. this piece of code will help u
data: var type string value 'hai',
len type i.
len = strlen(var).
write len. -
How to find length of string after encryption using DBMS_CRYPTO package
Hi,
I am planning do data encryption using DBMS_CRYPTO package. I want to find how much will be string length after encryption.
e.g When I try to encrypt string of length between 1-15 characters it gives me encrypted string of 32 characters. When I try with 16 charcters encrypted string is of 64 characters.
Is ther any formula to calculate length of encrypted string?
Thanks
PravinThe length change is dependent upon the algorithm you are using which can be a combination of cipher block, padding, and chaining.
The best solution is determine the method you are going to use and apply it to the l ongest possible strings you are going to proces, then add some safety margin. There iis no penalty for defining your column as VARCHAR2(4000).
Maybe you are looking for
-
Fastest way to create DVD Movies
I have a ton of Mini DV tapes that I want to convert into DVD's. I am not real interested in editing the content. I would just like to have DVD's with automatic chapters inserted either on each day change or on each event (camera record button presse
-
Is there a Lightning to thunderbolt adapter?
Is there a Lightning to thunderbolt adapter?
-
I believe in recycling instead of tossing things into garbage. I like to re-use good-quality printers that were discarded by others. If there is something a little wrong, I try to repair it and replace bad parts. Right now I am stumped. I bought a
-
Nokia Wireless Car Charger (CR200) Release Date
Is there any information on a release date for the Nokia Wireless Car Charger? I saw the intro of the product at MWC, and I'm really interested in purchasing one. I haven't been able to find any information regarding the release date though. Does any
-
Hi, I had a podcast in the iTunes store (Disembodied Voices was the name), but at some point it became outdated. I asked iTunes to delete it, and it was, my plan being to submit the new feed and start over. (In retrospect, a bad idea.) However, when