Finding the no of occurences of a string in a string array
hi
I have a string array which contains different strings say
for eg date
[21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 21/08/2008, 22/08/2008, 22/08/2008, 22/08/2008, 22/08/2008, 22/08/2008] etc.
for eg names
[coverage, search, search, combined-search, documentService, expand-term, id-mapping, citation, class, corporate-tree, document-update, coverage, coverage, search, search, combined-search, documentService, expand-term, id-mapping, citation, class, corporate-tree, document-update, coverage]
i need to find out the count of a particular date or name in the string array.
Also i will not be knowing what is the value that will be present in that string array.
the values are dynamic. please help to solve this.
thanks in advance
Mohan
In the same way use for date,names and other as required by you..sample code for nameimport java.io.*;
public class Test {
public static void main(String args[]) throws Exception{
int cnt=0;
String name[]={"coverage","abc","def","coverage", "search", "search"};
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter name");
String rv=br.readLine();
for(int i=0;i<name.length;i++){
if(rv.equals(name)){
cnt++;
System.out.println("Name occured "+cnt+" times");
Similar Messages
-
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] -
Finding the no. of occurence of a particular word in a paragraph.
Hi
If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
Paragraph: Desperate to avoid another market-crushing defeat, House leaders won key converts Thursday to the $700 billion financial industry bailout on the eve of a make-or-break second vote.President Bush and congressional leaders lobbied furiously for the dozen or so supporters they'd need to reverse Monday's stunning setback and approve a massive rescue plan designed to stave off national economic disaster.
"A lot of people are watching," Bush pointed out ? as if lawmakers needed reminding ? and he argued from the White House that the measure was the best chance to calm unnerved financial markets and ease a spreading credit crunch. Anything but reassured, investors sent the Dow Jones industrials plunging another 348 points lower.
ANY IDEA GUYS???ping.sumit wrote:
Hi
If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
...ping.sumit, you've been a (fairly) active member on these forums for almost a year now. Do you really have no idea how to begin solving this problem? -
How to find the special character in a give string/sentance
Hi All,
I have one task to complete with in the give time. Since i am not very good in PL/SQL i need your your help.
Requirement is :
I have to come up with the SQL or PL/SQL code which should return and find the special or hidden character in the datafiles name in a database. There are nearly 400+ database are present in almost all the flavor of UNIX and i have to check the each and every database.
As you know , Name of the data file will be like this :
/u02/instance_name\oradata\datafile_01.dbf So it should avoid these things and find out only the special characters in the datafile name.
a-z , A-Z , 0-9 and \ Please keep in mind that ...... I will be firing the Oracle script from Oracle 9i client which will access all the database from Oracle 9i to 11g in one short and give me the result.
Please help me to resolve this issue and let me know if you need more information.Hi,
Mukesh wrote:
Hi Frank,
This is excellent function. Thanks for you responce.
I want to modify this query in such a way that .... i should get only those datafiles name which are holding special characters. I don't know how to put this in where condition. :( Here's one way:
SELECT file_name
, ... -- other expressions, if you want any
FROM dba_data_files
WHERE TRANSLATE ( file_name
, '?0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ\_/abcdefghijklmnopqrstuvwxyz'
) IS NOT NULL Among the other expressions you can put into the SELECT clause (if you want to) is a copy of the TRANSLATE function, as you had in your message. That would highlight exactly which character(s) made the file_name invalid. -
Can't find the right way to parse a string
Hi to all,
I am new to Lab-View, coming from a "C" background. I have spent all afternoon trying to get something to work, with no success. I am looking for a way to read files that are named sequentially, with a common prefix. For example:
"abc2004_001.tst", "abc2004_002.tst",... .
These file are not generated by LabView and the problem is that the file counter does not have a fixed width (can be 2, 3, 4, ... character wide) and the file prefix is alpha_numeric.
What I would like to do is to select the first file in the sequence and let LabView generate all other name, incrementing the sequence number, until a file-not-found.
I've tried using regular expression but cannot make it work when the file name prefix contains
a number.
Any suggestion...
Thanks!
MichelBMichelB wrote in news:5065000000080000000BF00000-
[email protected]:
> Hi to all,
> I am new to Lab-View, coming from a "C" background. I have spent all
> afternoon trying to get something to work, with no success. I am
> looking for a way to read files that are named sequentially, with a
> common prefix. For example:
> "abc2004_001.tst", "abc2004_002.tst",... .
> These file are not generated by LabView and the problem is that the
> file counter does not have a fixed width (can be 2, 3, 4, ...
> character wide) and the file prefix is alpha_numeric.
> What I would like to do is to select the first file in the sequence
> and let LabView generate all other name, incrementing the sequence
> number, until a file-not-found.
> I've tried usin
g regular expression but cannot make it work when the
> file name prefix contains a number.
> Any suggestion...
> Thanks!
> MichelB
Suggestion 1:
Use the "Scan From String" function
(Function palette->String->Scan From String)
Wire your input string to "Input String"
Wire this string constant "%[^_]_%d" to "Format String"
Expand the outputs to get two outputs.
The format string does this (string is divided in three)
%[^_] Extract all characters which is not _
_ Match the _
%d Exctract a decimal number
Suggestion 2:
Use the "Match Pattern" function
(Function palette->String->Match Pattern)
with the string "[a-zA-Z0-9]_" as the "regular pattern" input
The "after substring" output should hold the number(+filename ending)
If you have an array with input file names (e.g. from the "List Directory"
file function) then you have to use a for or while loop.
Hope this helps.
Rolf -
Find the last character in an aplhanumreic string
Hi guys first time poster long time hiding in the shadows,
hopefully someone can help me
I have set of username stored and I need to find the last
character before the number for example
abc123 I would want to find c
ab123 I would want to find b
any suggestions as to how I would do this?
Thanks in advanceHere's one way:
<CFSET YourString = "abc123")>
<CFSET LastChar = "">
<CFSET Pos = 1>
<CFSET CharLen = Len(YourString)>
<CFLOOP from="1" to="#CharLen#" step="1">
<CFSET Char = right(left(YourString,Pos),1)>
<CFIF Not IsNumeric(Char)>
<CFSET LastChar = Char>
<CFSET Pos = Pos + 1>
<CFELSE>
<CFBREAK>
<CFIF>
</CFLOOP> -
Finding the number of occurance in a string
Hi Can someone tell me if there is a function to tell me how many times a string occurs in another string for example how many times does
"cat"
appear in
"cat dog catcat dogdog cat cat"Praveen_Forum wrote:
Try in the similar lines
String name = "cat dog catcat dogdog cat cat";
char pattern = 'c';
int occurs = 0;
for(int i = 0; i < name.length(); i++) {
char next = name.charAt(i);
if(next == pattern) {
occurs++;
System.out.println("Occurs " + occurs + " time(s)");
for a string:
String name = "cat dog catcat dogdog cat cat";
String toFind = "cat";
int occurs = 0;
for(int i = 0; i < name.length()-toFind.length()+1; i++)
if (name.substring(i, i+toFind.length()).equals(toFind))
occurs++;
System.out.println(occurs); -
How to find the largest odd number and smallest even number from an array
Hello All
I want to find out largest odd number and the smallest even number from an arry numbers? What is the best method to achieve this.
Thanks
SravzYou need to sit down and figure out an algo on how you would do it if you had to do the same thing from a blind container perspective:
1 - collect all the items you want to look at
2 - look at an item
3 - is it odd?
4 - if it is odd then check if it is larger than previously largest number
5 - save it if it is larger
6 - return back to 2 unless no more items
7 - item is not odd so it must be even--is it smaller than previous
8 - save it if it is smaller
9 - return back to 2 unless no more items
Now you just need to know how to check if something is even or odd: to do this you will need the modulous operator--integer division.
Note: this all assumes that your needs are for integer type of numbers, otherwise there is not enough information to define an answer. For instance, if you are using floats at 0.5--it that even or odd? Do you consider an err factor when dealing with floats? etc... -
Help:Can not find the file in jar!
Hello everyone:
I build a project using Netbeans 5.0 and make a jar file with it...
The code in the project as follows will throw an exception described that it can not find the file named datasource-config.xml
String dataFilePath = getClass().getResource(dataFile).getPath();
//System.out.println("filepath:"+dataFilePath);
InputStream input = new FileInputStream(dataFilePath);
when I run the project with the main() function as an entry it works perfectly and output:
filepath:/C:/projects/java_project/search/build/classes/com/cn/wxjt/lucene/config/datasource-config.xml
But when I compressed the project with jar and run it , it will show:
filepath:file:/C:/projects/java_project/search/dist/search.jar!/com/cn/wxjt/lucene/config/datasource-config.xml
there is a (!) between search.jar and /com/cn/wxjt...
I dont know why I generate a ! symbol in the file path... Is it cause the exception->
java.io.FileNotFoundException: file:\C:\projects\java_project\search\dist\search.jar!\com\cn\wxjt\lucene\config\datasource-config.xml
If you have any idea, plz tell me.
Thank you and best wishes to you !
:)If the file you want to read is in your jar file, use
getClass ().getResourceAsStream
(relative_path_file_name)Hope that help,
Jackhey jack i want to open the file as new File
i m using this.getClass().getResource("resource/backend.xml");
the resource is the directory inside the jar file.
when i prints the url it shows:
the jar file is in the WORK directory
URL : jar:file:/home/neeraj/WORK/show.jar!/resource/backend.xml
now when i creates new File using the url.getFile() method the file does not exist.
although the same programs runs well when i uses the InputStream
so plz tell me cant I create a new File from the above method????
thanks in advance
with regards
neeraj -
How to find the type of a variant...
I'm trying to programatically read the "VersionInfoFileVersionBuild" tag's value associated with a Build Specification. This is the fourth number in the overall version number. i.e if the version number is "1.4.3.7", the VersionInfoFileVersionBuild is 7.
I tried using the "Get Tag" method, with this tag, but the value is returned as a variant. I've tried converting this variant to data and I keep getting the following error: "LabVIEW: The data type of the variant is not compatible with the data type wired to the type input."
I've tried every numeric type and even strings and the same error keeps coming up. Can someone tell me what IS the type of the value associated with the "VersionInfoFileVersionBuild", or how do I find it?Hey intvsteve,
Thanks for trying to help. I had already tried using I32 as the type input for the "Variant to Data.vi" and it had not worked. I have even tried flattening the variant to a string and scanning the string. None of it has worked. For whatever reason, I'm getting a '4' back for the first element in my "Type String" array which indicates the type is a 64-bit integer. But that's not working for me either. I wonder if the problem has to do with this note in the Help for the Type Descriptors:
"Note The format in which LabVIEW stores type descriptors changed in LabVIEW 8.0. LabVIEW 7.x stores type descriptors in 16-bit flat representation. LabVIEW 8.0 stores type descriptors in 32-bit flat representation. The following information applies if you use the Convert 7.x Data mode of the Flatten to String function.Note The format in which LabVIEW stores type descriptors changed in LabVIEW 8.0. LabVIEW 7.x stores type descriptors in 16-bit flat representation. LabVIEW 8.0 stores type descriptors in 32-bit flat representation. The following information applies if you use the Convert 7.x Data mode of the Flatten to String function."
I'm using LabVIEW 8.0. Any other thoughts? -
How can I find the full width at half-maximum?
Hello,
I have run into a problem that I hope you can help me with: I need to find the Full Width at Half-Maximum.
I have an array of pixel intensities and have found the peaks and valleys using Peak Detector.vi, but I can not figure out a way to find the full width at half-maximum (the width of the 'hill' at one-half of its maximum point).
Any help you may provide would be greatly appreciated.
Jared Leisner
- Using LabVIEW 6.1/Vision 6.0Jared,
I had the same problem. One of the solutions I used was to use the was to
use "threshold 1D array.vi" from the array palette. You can use this to
iteratively get the uphill edge of the peak. To get the down hill edge, you
have to invert the array and then use the same VI. Then subract the uphil
position from the down hill position and your done.
You do however need to be careful depending on your image content. If the
image is noisy, then the "Peak Detector.vi" will have problems finding the
"real peak".
Steven Bloomberg
CISTech
"Jared Leisner" wrote in message
news:[email protected]..
> Hello,
>
> I have run into a problem that I hope you can help me with: I need
> to find the Full Width at
Half-Maximum.
> I have an array of pixel intensities and have found the peaks and
> valleys using Peak Detector.vi, but I can not figure out a way to find
> the full width at half-maximum (the width of the 'hill' at one-half of
> its maximum point).
> Any help you may provide would be greatly appreciated.
>
> Jared Leisner
> - Using LabVIEW 6.1/Vision 6.0 -
How to use a WebService Model with String Arrays as its input parameter
Hi All,
I am facing the following scenario -
From WebDynpro Java i need to pass 2 String Arrays to a Webservice.
The Webservice takes in 2 input String Arrays , say, Str_Arr1[] and Str_Arr2[] and returns a string output , say Str_Return.
I am consuming this WebService in WebDynpro Java using WEB SERVICE MODEL. (NWDS 04).
Can you please help out in how to consume a WSModel in WD where the WS requires String Arrays?Hi Hajra..
chec this link...
http://mail-archives.apache.org/mod_mbox/beehive-commits/200507.mbox/<[email protected]>
http://www.theserverside.com/tt/articles/article.tss?l=MonsonHaefel-Column2
Urs GS -
Two dimension string array in teststand
Hello,
I want to pass a two dimension string array from a labWindows dll into Teststand. My labwindows dll:
#define NR_columns 12
#define NR_rows 1200
#define NR_hight 1024
int__declspec(dllexport) __stdcall sort( char pspec[NR_columns][NR_rows][NR_hight])
The call of the dll in teststand looks like the attached picture in the doc file.
and I got the error message which shows the attached second picture in the doc file
what is the problem?
regards
samuel
Attachments:
Error1.doc 94 KBHello Samuel,
I'm not experienced in LabWindows but I think the reason for this Error is the dimension of FileGlobals.loadspec in TestStand. The Error Dialog displays for this String Array [0..11][0..1200]. That's an array of 12 and 1201 elements but function is expecting 12 and 1200 elements.
I hope this helps.
Kind regards
C. Dietz
Test Engineering
digades GmbH
www.digades.com -
I use the following code to populate a string array:
File dirFile = new File("C:\\somedir");
String fileImport[] = dirFile.list();
This gives me a string array with a whole bunch of files in the following format:
XXXDDMMYYHHMISS.xml
What I need to know is what is the easiest way to sort this array based on this date format, or any date format, in the ascending order, so that when I am loading my XML files, I get the oldest one first.
Appreciate any input.
SamUse the String name of the file (the Date part), together with a java.text.SimpleDateFormat object to parse() the String. You have to set the formatter with a pattern - these are explained fully in the Javadocs for the SimpleDateFormat class. After parsing, you will have java.util.Date objects for each of the files - you can then use these as keys in a java.util.SortedMap (the values would be the files) - the natural ordering of dates will ensure that they are ordered appropriately
Maybe you are looking for
-
U00A8Wait Step doesnu00B4t finnish...
I have a Wait Step in my bpm and it never finnishes the execution, it stays running forever. I´m running sp20. Is there any bug ? Thanks
-
What is the meaning of MAIN_OBJECT field in table CRMD_SRV_REFOBJ
Hi, Please help me in understanding the meaning of MAIN_OBJECT field in table CRMD_SRV_REFOBJ Thanks Sudhansu
-
Is this bug of password security in Acrobat 9?
If you set password to "abcde" you can release it by input just "mz". Or when longer password like "ABC-123456." then just input "x" to unsecure it. I test on Acrobat 9.3.4. If so, it is easy to unsecure all of secured pdf.
-
Trackpad doesn't work for 5 seconds after any USB device is connected
This is really irritating. I could plug in any USB device - a hard drive or iPhone, and the trackpad will not work for about seconds of trying to get the pointer to move around the screen. Normally there's nothing connected to the Mac, so when someth
-
IMessage on Mountain Lion sending broken links to iOS
OS 10.8.4 iMessage (Jabber Account [Gmail?]) is not sending links to iOS correctly. They are a long mangled mess that the recipient cannot click on. I have tried using URL shortening services but the same think occurs. The link is repeated about 15 t