startswith

Why is function isprefix faster than Startswith in C#?

与世无争的帅哥 提交于 2019-12-03 00:15:33
Does anyone know why C# (.NET)'s StartsWith function is considerably slower than IsPrefix ? I think it's mostly fetching the thread's current culture. If you change Marc's test to use this form of String.StartsWith : Stopwatch watch = Stopwatch.StartNew(); CultureInfo cc = CultureInfo.CurrentCulture; for (int i = 0; i < LOOP; i++) { if (s1.StartsWith(s2, false, cc)) chk++; } watch.Stop(); Console.WriteLine(watch.ElapsedMilliseconds + "ms; chk: " + chk); it comes a lot closer. If you use s1.StartsWith(s2, StringComparison.Ordinal) it's a lot faster than using CompareInfo.IsPrefix (depending on

How do I select by a range of starting characters?

北城以北 提交于 2019-12-02 06:30:14
问题 Here is my mySQL query: SELECT * FROM `eodList` WHERE datechanged>='$curdate' GROUP BY symbolName ORDER BY dateChanged DESC How do I get all rows (for example) where symbolName starts with letters A-F ? Update: I need something that can be easily changed to another range without alot of code changes. 回答1: Try with Regex WHERE symbolName REGEXP '^[A-F]' 回答2: Faster than Regular expressions and SUBSTRING() function calls. This will use the index of symbolName : WHERE symbolName >= 'A' AND

How to find a file using a variable for 'Startswith' in Java

扶醉桌前 提交于 2019-12-02 04:10:52
I'm trying to find a file based on the first 8 numbers i pull from an excel sheet for each iteration. Whenever I use the code below I get the error message "Local variable CaseID defined in an enclosing scope must be final or effectively final". I'm still new so i'm not sure how to fix this even though it sounds like a simple fix. The issue is happening at the caseID variable towards the bottom of the code. package Chrome; //CHROME import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FilenameFilter; import org.apache

How do I select by a range of starting characters?

不问归期 提交于 2019-12-02 03:16:20
Here is my mySQL query: SELECT * FROM `eodList` WHERE datechanged>='$curdate' GROUP BY symbolName ORDER BY dateChanged DESC How do I get all rows (for example) where symbolName starts with letters A-F ? Update: I need something that can be easily changed to another range without alot of code changes. Try with Regex WHERE symbolName REGEXP '^[A-F]' Faster than Regular expressions and SUBSTRING() function calls. This will use the index of symbolName : WHERE symbolName >= 'A' AND symbolName < 'G' There is an issue with the case sensitivity though. Do you want names which start with a..f too or

Regular Expression To Match String Not Starting With Or Ending With Spaces

走远了吗. 提交于 2019-12-02 03:08:01
问题 I need a regular expression that makes sure a string does not start with or end with a space. I don't care if it has a space in the "middle" just not at the beginning or the end. I have a regular expression that almost works: ^\S.*\S$ Here are some example results: "HELLO" (Match) "HEL LO" (Match) " HELLO" (No Match) "HELLO " (No Match) "H" (No Match) As you can see, the issue I am having is that when the string is only 1 character long ("H" in the example above) it doesn't return a match.

Regular Expression To Match String Not Starting With Or Ending With Spaces

吃可爱长大的小学妹 提交于 2019-12-02 02:10:19
I need a regular expression that makes sure a string does not start with or end with a space. I don't care if it has a space in the "middle" just not at the beginning or the end. I have a regular expression that almost works: ^\S.*\S$ Here are some example results: "HELLO" (Match) "HEL LO" (Match) " HELLO" (No Match) "HELLO " (No Match) "H" (No Match) As you can see, the issue I am having is that when the string is only 1 character long ("H" in the example above) it doesn't return a match. How do I modify my regular expression to handle the case where the string length is 1? Thank you NOTE - I

Xpath - Selecting attributes using starts-with

≯℡__Kan透↙ 提交于 2019-12-01 15:28:20
I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar. Below is a snippet of the HTML that I am looking at: <td class="some class" align="center" onclick="Calendar_DayClicked(this,'EventCont','Event');"> <span class="Text"></span> <div id="CompanyCalendar02.21" class="Pop CalendarClick" style="right: 200px; top: 235px;"></div> There are multiple divs that have an id like CompanyCalendar02.21 but for each new month in the calendar, they change the id. For example, the next month would be CompanyCalendar02.22. I would like to

sum values of columns starting with the same string in pandas dataframe

时间秒杀一切 提交于 2019-12-01 05:10:37
I have a dataframe with about 100 columns that looks like Id Economics-1 English-107 English-2 History-3 Economics-zz Economics-2 \ 0 56 1 1 0 1 0 0 1 11 0 0 0 0 1 0 2 6 0 0 1 0 0 1 3 43 0 0 0 1 0 1 4 14 0 1 0 0 1 0 Histo Economics-51 Literature-re Literatureu4 0 1 0 1 0 1 0 0 0 1 2 0 0 0 0 3 0 1 1 0 4 1 0 0 0 so my goal is to leave only more global categories : just English, History, Literature, and write in these dataframe the sum of the value of its' components, for instance for English: English-107, English-2 Id Economics English History Literature 0 56 1 1 2 1 1 11 1 0 0 1 2 6 0 1 1 0 3

Determine if string starts with letters A through I

烈酒焚心 提交于 2019-12-01 03:35:48
I've got a simple java assignment. I need to determine if a string starts with the letter A through I. I know i have to use string.startsWith(); but I don't want to write, if(string.startsWith("a")); all the way to I, it seems in efficient. Should I be using a loop of some sort? You don't need regular expressions for this. Try this, assuming you want uppercase only: char c = string.charAt(0); if (c >= 'A' && c <= 'I') { ... } If you do want a regex solution however, you can use this ( ideone ): if (string.matches("^[A-I].*$")) { ... } if ( string.charAt(0) >= 'A' && string.charAt(0) <= 'I' ) {

jQuery select div with ID and class

陌路散爱 提交于 2019-12-01 01:04:54
I have the following: <article id="post-43" class="like"></article> <article id="post-56" class="like"></article> <article id="post-78" class="dislike"></article> <article id="bob" class="like"></article> I want to hide all the articles that have ID beginning with "post-" that also have the class "like" using jQuery. I have tried this: $('#show_likes').on('click', function() { $('input[name^="post-"].like').hide(); }); But it doesn't work. Can someone help? Use article instead of input ,and id instead of name : $('article[id^="post-"].like').hide(); 来源: https://stackoverflow.com/questions