compare

std::string comparison (check whether string begins with another string)

点点圈 提交于 2019-11-29 20:47:41
I need to check whether an std:string begins with "xyz". How do I do it without searching through the whole string or creating temporary strings with substr(). I would use compare method: std::string s("xyzblahblah"); std::string t("xyz") if (s.compare(0, t.length(), t) == 0) { // ok } Neutrino An approach that might be more in keeping with the spirit of the Standard Library would be to define your own begins_with algorithm. #include <algorithm> using namespace std; template<class TContainer> bool begins_with(const TContainer& input, const TContainer& match) { return input.size() >= match.size

Quickly find differences between two large text files

烈酒焚心 提交于 2019-11-29 18:23:00
问题 I have two 3GB text files, each file has around 80 million lines. And they share 99.9% identical lines (file A has 60,000 unique lines, file B has 80,000 unique lines). How can I quickly find those unique lines in two files? Is there any ready-to-use command line tools for this? I'm using Python but I guess it's less possible to find a efficient Pythonic method to load the files and compare. Any suggestions are appreciated. 回答1: If order matters, try the comm utility. If order doesn't matter,

Most efficient way to return common elements from two string arrays

旧时模样 提交于 2019-11-29 18:11:14
问题 In Java, what's the most efficient way to return the common elements from two String Arrays? I can do it with a pair of for loops, but that doesn't seem to be very efficient. The best I could come up with was converting to a List and then applying retainAll , based on my review of a similar SO question: List<String> compareList = Arrays.asList(strArr1); List<String> baseList = Arrays.asList(strArr2); baseList.retainAll(compareList); 回答1: EDITED: This is a one-liner: compareList.retainAll(new

How to compare 2 strings and find the difference in percentage? [closed]

孤街浪徒 提交于 2019-11-29 18:05:57
I am new to C#. I have 2 strings, they are representing characters from International Phonetic Alphabet. String 1 - ðə ɻɛd fɑks ɪz hʌŋgɻi String 2 - ðæt ɪt foks ɪn ðʌ sʌn ɻe͡i Now I need to compare String 1 with String 2 and find how much String 2 differ from String 1 . I need this value as a percentage value. How can I do this? Small code example will help me a lot. Your help will be greatly appreciated. Ofiris You should have tell what is your String Metric Also, have a look in this How to find difference between two strings - C# question. This will compare char by char, it is different than

How to compare char variables (c-strings)?

六眼飞鱼酱① 提交于 2019-11-29 17:45:28
#include <iostream> using namespace std; int main() { char word[10]="php"; char word1[10]="php"; if(word==word1){ cout<<"word = word1"<<endl; } return 0; } I don't know how to compare two char strings to check they are equal. My current code is not working. Use std::string objects instead: #include <iostream> #include <string> using namespace std; int main() { string word="php"; string word1="php"; if(word==word1){ cout<<"word = word1"<<endl; } return 0; } Pubby Use strcmp. #include <cstring> // ... if(std::strcmp(word, wordl) == 0) { // ... } To justify c++ tag you'd probably want to declare

awk Compare 2 files, print match and difference

我们两清 提交于 2019-11-29 17:22:20
I need to comapre two files f1.txt and f2.txt and obtain matches, and non-matches, for this case I am looking to match first field on both files. And print first the second field of f2.txt, then print the entire line of f1.txt. And for no match found on f2.txt to state "Not Found" and then print f1.txt entire line. F1.txt 1;2;3;4;5;6;7;8 1a;2;3;4;5;6;7;8 1b;2;3;4;5;6;7;8 2b;2;3;4;5;6;7;8 F2.txt 1;First 1a;Firsta 1b;Firstb Desired output: First;1;1;2;3;4;5;6;7;8 Firsta;1a;1a;2;3;4;5;6;7;8 Firstb;1b;1b;2;3;4;5;6;7;8 Not Found;2b;2;3;4;5;6;7;8 I am able to obtain the matches but not the non match

Compare a NSNumber to an int

自古美人都是妖i 提交于 2019-11-29 16:49:33
问题 I've a simple question (I think): I'm trying to compare a NSNumber with a int, to see if it is 0 or 1. Here is the code: id i = [dictionary objectForKey:@"error"]; //class = NSCFNumber NSLog(@"%@ == 0 -> %@", i, i == 0); NSLog(@"%@ == 0 -> %@", i, [i compare:[NSNumber numberWithBool:NO]]); I tried this to methods but I get null as result: 2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null) 2010-10-17 21:57:49.065 Api[15152:a0f] 0 == 0 -> (null) Can you help me? 回答1: The result of

Getting the old value and new value between two revisions with Hibernate Envers

ぐ巨炮叔叔 提交于 2019-11-29 16:44:49
This is a follow up question to Retrieve audited entities name, old value and new value of the given revision I have figured out how to get the two revision of an entity but don't see any easy to find the difference between the two. Is there anything in envers that will help doing a diff of an entity at different revisions? Or any good libraries? I would be really cool if I could get the property modified (_mod) field fields. So what I came up with to make life easier was to create an annotation to mark the fields I was interested in comparing. Without I ended up having to get with sticking to

regex compare two numbers

白昼怎懂夜的黑 提交于 2019-11-29 16:19:47
can i somehow compare two numbers in regex? i want regex that is correct for 10-12, but incorrect for 12-10. I mean that 10 must be smaller than 12. I want to do it in Javascript. If the input is always of the form X-Y, then why not use the split() function with '-' as the delimiter and then compare the two parts with > You can't compare numerical values using RegExps. I wouldn't use regex for this. I'd split the string on the operator, then compare the two resulting numbers based on what operator I found (I'm assuming 10+12 and 12+10 would both be legal). The problem here is that you're

KeyNotFoundException in filled dictionary

微笑、不失礼 提交于 2019-11-29 16:12:27
I am trying to modify value in dictionary, but the compiler throws KeyNotFoundException . I'm sure, I declared that key in dictionary, because I am calling GenerateEmptyChunks() method, which fills dictionary with chunks with key of their position and values are empty for level generator. I've checked debugger and Chunks dictionary object is correctly filled with keys and values. Is it caused by my unworking CompareTo method? If yes, how I have modify CompareTo method to return right values? public Dictionary<WPoint, WChunk> Chunks = new Dictionary<WPoint, WChunk>(); GenerateEmptyChunks()