EzDevInfo.com

wildcard interview questions

Top wildcard frequently asked interview questions

Wildcard search for LINQ

I would like to know if it is possible to do a wildcard search using LINQ.

I see LINQ has Contains, StartsWith, EndsWith, etc.

What if I want something like %Test if%it work%, how do I do it?

Regards


Source: (StackOverflow)

List files not matching a pattern?

Here's how one might list all files matching a pattern in bash:

ls *.jar

How to list the complement of a pattern? i.e. all files not matching *.jar?


Source: (StackOverflow)

Advertisements

Pattern matching using a wildcard

How do I identify a string using a wildcard?

I've found glob2rx, but I don't quite understand how to use it. I tried using the following code to pick the rows of the data frame that begin with the word blue:

# make data frame
a <- data.frame( x =  c('red','blue1','blue2', 'red2'))

# 1
result <- subset(a, x == glob2rx("blue*") )

# 2
test = ls(pattern = glob2rx("blue*"))
result2 <- subset(a, x == test )

# 3
result3 <- subset(a, x == pattern("blue*") )

However, neither of these worked. I'm not sure if I should be using a different function to try and do this.


Source: (StackOverflow)

Stop shell wildcard character expansion?

Is there any way for a compiled command-line program to tell bash or csh that it does not want any wildcard characters in its parameters expanded?

For instance, one might want a shell command like:

foo *

to simply return the numeric ASCII value of that character.


Source: (StackOverflow)

Python subprocess wildcard usage

import os

import subprocess

proc = subprocess.Popen(['ls','*.bc'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out,err = proc.communicate()

print out

This script should print all the files with .bc suffix however it returns an empty list. If I do ls *.bc manually in the command line it works. Doing ['ls','test.bc'] inside the script works as well but for some reason the star symbol doesnt work.. Any ideas ?


Source: (StackOverflow)

How to implement a SQL like 'LIKE' operator in java?

I need a comparator in java which has the same semantics as the sql 'like' operator. For example:

myComparator.like("digital","%ital%");
myComparator.like("digital","%gi?a%");
myComparator.like("digital","digi%");

should evaluate to true, and

myComparator.like("digital","%cam%");
myComparator.like("digital","tal%");

should evaluate to false. Any ideas how to implement such a comparator or does anyone know an implementation with the same semantics? Can this be done using a regular expression?


Source: (StackOverflow)

Google Spreadsheet, Count IF contains a string

I have a column like this:

What devices will you be using?

iPad
Kindle & iPad
No Tablet
iPad
iPad & Windows

How do I count the amount of people that said iPad?

This formula does work for exact matches but not if it contains an additional value:

=(COUNTIF(A2:A51,"=iPad")/COUNTA(A2:A51))*1

Any Suggestions?


Source: (StackOverflow)

Search for a file using a wildcard

I want get a list of filenames with a search pattern with a wildcard. Like:

getFilenames.py c:\PathToFolder\*
getFilenames.py c:\PathToFolder\FileType*.txt
getFilenames.py c:\PathToFolder\FileTypeA.txt

How can I do this?


Source: (StackOverflow)

Sum all columns with a wildcard name search using Python Pandas

I have a dataframe in python pandas with several columns taken from a CSV file.

For instance, data =:

Day P1S1 P1S2 P1S3 P2S1 P2S2 P2S3
1   1    2    2    3    1    2
2   2    2    3    5    4    2

And what I need is to get the sum of all columns which name starts with P1... something like P1* with a wildcard.

Something like the following which gives an error:

P1Sum = data["P1*"]

Is there any why to do this with pandas?


Source: (StackOverflow)

SQL LIKE with no wildcards the same as '='?

I know this is a pretty basic question, and I think I know the answer...but I'd like to confirm.

Are these queries truly equivalent?

SELECT * FROM FOO WHERE BAR LIKE 'X'
SELECT * FROM FOO WHERE BAR ='X'

Perhaps there is a performance overhead in using like with no wild cards?

I have an app that optionally uses LIKE & wild cards. The SP currently does the like and appends the wild cards -- I am thinking of just updating the query to use like but have the app append the wild cards as needed.


Source: (StackOverflow)

SQL Server using wildcard within IN

Since I believe this should be a basic question I know this question has probably been asked, but I am unable to find it. I'm probably about to earn my Peer Pressure badge, but I'll ask anyway:

Is there a way in SQL Server that I am not aware of for using the wildcard character % when using IN.

I realize that I can use OR's like:

select *
from jobdetails
where job_no like '0711%' or job_no like '0712%'

and in some cases I can use a subquery like:

select *
from jobdetails
where job_no in (select job_no from jobs where job_id = 39)

but I'm looking to do something like the following:

select *
from jobdetails
where job_no in ('0711%', '0712%')

In this case it uses the percent sign as a character instead of a wildcard character so no rows are returned. I currently just use a bunch of OR's when I have to do this, but I know there has to be a better way. What method do you use for this?


Source: (StackOverflow)

How to use the .* wildcard in bash but exclude the parent directory (..)?

There are often times that I want to execute a command on all files (including hidden files) in a directory. When I try using

chmod g+w * .*

it changes the permissions on all the files I want (in the directory) and all the files in the parent directory (that I want left alone).

Is there a wildcard that does the right thing or do I need to start using find?


Source: (StackOverflow)

How to determine if a List is sorted in Java?

I would like a method that takes a List<T> where T implements Comparable and returns true or false depending on whether the list is sorted or not.

What is the best way to implement this in Java? It's obvious that generics and wildcards are meant to be able to handle such things easily, but I'm getting all tangled up.

It would also be nice to have an analogous method to check if the list is in reverse order.


Source: (StackOverflow)

CS1607: The version specified for the 'file version' is not in the normal 'major.minor.build.revision' format in .NET

I am trying to set my AssemblyVersion and AssemblyFileVersion attributes in my project like so:

[assembly: AssemblyVersion("3.0.*")]
[assembly: AssemblyFileVersion("3.0.*")]

but I get this warning:

CS1607: Assembly generation -- The version '3.0.*' specified for the 'file version' is not in the normal 'major.minor.build.revision' format

On the AssemblyVersionAttribute Class page at MSDN is the following:

You can specify all the values or you can accept the default build number, revision number, or both by using an asterisk (*). For example, [assembly:AssemblyVersion("2.3.25.1")] indicates 2 as the major version, 3 as the minor version, 25 as the build number, and 1 as the revision number. A version number such as [assembly:AssemblyVersion("1.2.*")] specifies 1 as the major version, 2 as the minor version, and accepts the default build and revision numbers. A version number such as [assembly:AssemblyVersion("1.2.15.*")] specifies 1 as the major version, 2 as the minor version, 15 as the build number, and accepts the default revision number.

Note the bold section. Does anyone know why [assembly: AssemblyVersion("3.0.*")] (from my project) is not valid, but [assembly:AssemblyVersion("1.2.*")] (from the MSDN example) is valid?

In particular, I am curious to know if I can start with a non-zero major number, as the application that I am writing is version 3 of the program.

UPDATE >>> Sorry, this does seem to be answered in the other post... please vote to close it, thanks.


Source: (StackOverflow)

What's the purpose behind wildcards and how are they different from generics?

I'd never heard about wildcars until a few days ago and after reading my teacher's Java book, I'm still not sure about what's it for and why would I need to use it.

Let's say I have a super class Animal and few sub classes like Dog, Cat, Parrot, etc... Now I need to have a list of animals, my first thought would be something like:

List<Animal> listAnimals

Instead, my colleagues are recommending something like:

List<? extends Animal> listAnimals

Why should I use wildcards instead of simple generics?

Let's say I need to have a get/set method, should I use the former or the later? How are they so different?


Source: (StackOverflow)