string q = "m";
Query query = new QueryParser("company", new StandardAnalyzer()).Parse(q+"*");
Run Code Online (Sandbox Code Playgroud)
将导致查询成为prefixQuery:company:a*
我仍然会得到像"舰队非洲"这样的结果,很明显A不是一开始就给我带来了不良后果.
Query query = new TermQuery(new Term("company", q+"*"));
Run Code Online (Sandbox Code Playgroud)
将导致查询成为termQuery:company:a*并且不返回任何结果.可能是因为它将查询解释为完全匹配,并且我的值都不是"a*"字面值.
Query query = new WildcardQuery(new Term("company", q+"*"));
Run Code Online (Sandbox Code Playgroud)
将返回与prefixquery相同的结果;
我究竟做错了什么?
我必须拿一根绳子并将其转换为猪拉丁。Piglatin 有三个规则,其中之一是:
如果英语单词以元音开头,则对于 Piglatin 版本,返回英语单词 +“yay”。
所以我诚实地尝试这样做,希望得到一个错误,因为startsWith()方法采用字符串作为参数,而不是数组。
public String pigLatinize(String p){
if(pigLatRules(p) == 0){
return p + "yay";
}
}
public int pigLatRules(String r){
String vowel[] = {"a","e","i","o","u","A","E","I","O","U"};
if(r.startsWith(vowel)){
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
但如果我不能使用数组我就必须做这样的事情
if(r.startsWith("a")||r.startsWith("A")....);
return 0;
Run Code Online (Sandbox Code Playgroud)
并测试每个不包括 y 的元音,这会占用非常大的空间,就我个人而言,我认为它看起来会相当混乱。
当我写这篇文章时,我正在考虑通过迭代来测试它。
String vowel[] = new String[10];
for(i = 0; i<vowel[]; i++){
if(r.startsWith(vowel[i]){
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道这种迭代尝试是否有意义。
选择器类可以是:
c-1
c-2
c-3
(etc...)
Run Code Online (Sandbox Code Playgroud)
选择器也可以有其他类,所以这里是一个可能的HTML示例:
<div class="foo c-2 foofoo"></div>
Run Code Online (Sandbox Code Playgroud)
我希望得到之后的数字c
.在这种情况下 - 我会得到2
.
我怎样才能做到这一点?
我有两个设备一个与Lollipop和一个与Kitekat ...一个与Lollipop没有报告任何错误,但当我尝试我的应用程序时,我得到此错误:
10-13 16:56:56.126: I/chromium(6322): [INFO:CONSOLE(99)] "Uncaught
TypeError: Object ALIM. IL SOLE DI LOPARDO MARIANGELA has no
method 'startsWith'", source: file:///android_asset/www/soggetti3.html (99)
Run Code Online (Sandbox Code Playgroud)
这是我的javascript的一部分:
function onDeviceReady() {
window.rancolor=ranColor();
var ricerca=localStorage.getItem('testo_ricerca');
var risultati = JSON.parse(localStorage["risultati"]);
var ricerca1=ricerca.toString();
ricerca1=ricerca1.toUpperCase();
var res_match=[];
var lll=risultati.length;
for(var r=0;r<lll;r++){
var ppp0=risultati[r][1].toString();
var ppp1=risultati[r][0].toString();
var ppp2=risultati[r][2].toString();
var ppp3=risultati[r][3].toString();
ppp0=ppp0.toUpperCase();
alert(ppp0);
alert(ricerca1);
var check=ppp0.startsWith(ricerca1);
if(check==true){
res_match=res_match.concat([[ppp1,ppp0,ppp2,ppp3]]);
}
}
var y=res_match.length;
Run Code Online (Sandbox Code Playgroud)
我应该如何搜索一个字符串数组,搜索以其他字符串开头的字符串?
我有2个列表,一个包含数字列表,另一个包含名称列表。我在名称的开头加上了第一个列表中的数字,然后加上了下划线。我想根据第一个列表中找到的所有数字过滤第二个列表。
我尝试过的。
List<String> numberList = new ArrayList<>();
numberList.add("1_");
numberList.add("9_");
List<String> nameList = new ArrayList<>();
nameList.add("1_John");
nameList.add("2_Peter");
nameList.add("9_Susan");
List<String> filteredList = Stream.of(numberList.toArray(new String[0]))
.filter(str -> nameList.stream().anyMatch(str::startsWith))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
上面的代码运行没有错误,但是filteredList为空。显然我做错了。
filteredList应该仅包含:
1_约翰
9_苏珊
当我尝试生成MappedItem类的列表时,我收到错误,见下文.简而言之,下面的代码示例尝试按类别,日期范围和SKU查找产品.我的要求是用户应该能够输入以逗号分隔的SKU列表,并且搜索是查找SKU以用户输入的某个SKU开始的任何产品.当我运行代码时,我得到了.
除Contains()运算符外,本地序列不能用于查询运算符的LINQ to SQL实现.
缩写序列是这样的:
将逗号分隔的SKU字符串转换为字符串列表.
string sku = TextSKU.Text;
List<string> skuList = sku.Split(new char[] { ',' }).ToList();
Run Code Online (Sandbox Code Playgroud)
在代码中的其他位置定义将接受搜索结果的类.
public class MappedItem
{
public string ItemDescription { get; set; }
public int ItemCount { get; set; }
public MappedItem()
{
}
public MappedItem(string itemDescription, int itemCount)
{
ItemDescription = itemDescription;
ItemCount = itemCount;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我生成结果的查询
List<MappedItem> widgetItems = (from c1 in db.CCRCodes
join pac in db.widgetAssignedCodes on c1.code_id equals pac.code_id
join ph in db.widgetHistories on pac.history_id equals ph.history_id
where …
Run Code Online (Sandbox Code Playgroud) 是否有字符串的StartsWith的扩展,它在字符串中的每个单词的开头搜索?
像:
"Ben Stiller".StartsWithExtension("Sti")
回归真实
我想要这个,所以我可以做一个搜索的谓词.
假设有一个名为Persons的列表,ICollection<Person>
每个人都有一个属性Name,其值为"Ben Stiller"或"Adam Sandler".
我希望能够做如下的谓词:
Persons.Where(p => p.Name.StartsWithExtension(query))
谢谢(欢迎其他更好的方法来实现这一目标)
我是C#的新手,我遇到了问题.
我有2个List,2个字符串和一个getCombinations(字符串)方法,它返回字符串的所有组合作为List;
我如何验证一个subjectStrings元素是否没有StartWith &&!EndsWith &&!包含(或者!StartWith &&!EndsWith && Contains等)每个startswithString,endswithString和containsString的组合?
这是我的代码在StartWith &&!EndsWith(如果你想看到它运行:http://ideone.com/y8JZkK )
using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
{
List<string> validatedStrings = new List<string>();
List<string> subjectStrings = new List<string>()
{
"con", "cot", "eon", "net", "not", "one", "ten", "toe", "ton",
"cent", "cone", "conn", "cote", "neon", "none", "note", "once", "tone",
"cento", "conte", "nonce", "nonet", "oncet", "tenon", "tonne",
"nocent","concent", "connect"
}; //got a more longer wordlist
string startswithString = "co";
string endswithString = "et"; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个正则表达式,它接受一个单词,对于以元音开头的单词返回 true,对于以辅音开头的单词返回 false。我以前从未写过正则表达式,我对如何编写表达式有点困惑。这是我到目前为止:
def starts_with_a_vowel?(word)
if word.match(/\A+[aeiou]/) == true
return true
else
return false
end
end
Run Code Online (Sandbox Code Playgroud)
编辑:所以如果 word = "boat" ,表达式应该返回 false。如果 word = "apple",则表达式应返回 true。
我有一个带有文本列的pandas数据框。
我想创建一个新列,其中的值取决于text列中文本字符串的开头。
因此,如果text列的前30个字符是:
=='xxx ... xxx'然后返回值1 /
=='yyy ... yyy'然后返回值2
=='zzz ... zzz'然后返回值3
如果以上都不返回0
startswith ×10
c# ×2
java ×2
linq ×2
string ×2
android ×1
arrays ×1
autosuggest ×1
class ×1
combinations ×1
contains ×1
cordova ×1
java-8 ×1
java-stream ×1
javascript ×1
jquery ×1
linq-to-sql ×1
lucene.net ×1
pandas ×1
python ×1
regex ×1
ruby ×1
search ×1