w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
BASH comparing version numbers
It is doing a lexical comparison. Use one of these: if [ $(version $phpver) -gt $(version 5.2.13) ] || [ $(version $phpver) -lt $(version 5.2.13) ]; then if [[ $(version $phpver) > $(version 5.2.13) ]] || [[ $(version $phpver) < $(version 5.2.13) ]]; then if (( $(version $phpver) > $(version 5.2.13) )) || (( $(version $phpver) < $(version 5.2.13) )); then Or do it all in awk or some other tool. It is screaming for some optimisation. It also seems you're not producing numbers either, so you have a pretty odd design. Usually the version substrings are multiplied by 1000 and then all summed up to get a single comparable scalar.

Categories : Bash

Comparing UTC date/time strings in Bash
Here's how I would do it: with sort. dates=( 2013-08-09T14:20:47.000Z 2013-08-09T14:31:47.000Z ) latest=$(for date in ${dates[@]} do echo $date done | sort | tail -n 1) echo $latest # outputs "2013-08-09T14:31:47.000Z" This is obviously just a sample script, modify as needed - it could easily be turned into a function like: function latest() { local dates="$@" for date in ${dates[@]} do echo $date done | sort | tail -n 1 } latest ${dates[@]} # outputs "2013-08-09T14:31:47.000Z"

Categories : Arrays

Bash script trouble with comparing strings
You should add spaces. Treat [[ or [ as if it's another command like test and other builtins. And like other commands, it requires a space after its name. It's also recommended that you use [[ ]] over [ ] in Bash since [[ ]] doesn't split its variables with IFS and do pathname expansions. It also has more features over the other. #!/bin/bash STR="Hello World" if [[ $STR = "Hello World" ]]; then echo "passed test" else echo "didn't pass test" fi

Categories : Bash

git alias with bash conditional logic comparing strings - syntax issues
You could try either the character code of the character you want, or the hex name of the character you want. Here is a link to these things: http://www.utf8-chartable.de/ At the core of what you are doing, you are just writing a bash script in your environment. So whatever lets you write quotes outside of git's bash interface should be able to work here.

Categories : GIT

Java excel - Comparing two strings
The first mismatch in the above code will cause null to be returned without checking subsequent row values. More than likely, this is the scenario you are describing. Check all cell values before resorting to returning null when the attempted match fails. for (int i = 0; i < lastRow; i++) { Row row = sheet.getRow(i); Cell cell = row.getCell(jobCod); String tmp = cell.getRichStringCellValue().getString().toLowerCase(); if (tmp.equals(jobName)) { return tmp; } } return null; // now return null

Categories : Java

comparing two strings in java - compareTo
The exception probably comes from this line. Arrays.sort(student); Internally Arrays.sort() will attempt to cast elements of the passed array to Comparable, this so it can call their compareTo() method. That is why you get a class cast exception. Student must implement Comparable. Don't use your own IComparable interface, instead use java.lang.Comparable.

Categories : Java

Exception:java.lang.NullPointerException when comparing two strings of two different string arrays
I guess you assume that your array of strings is sorted, otherwise your killDuplicate method wouldn't make sense at all. The problem with your code is that in the second for loop in killDuplicate method you iterate with condition counter2 < counter which says iterate until all found duplicates are passed. So when you find your last duplicate you exit without filling the rest of the array. Try with example: new String[]{"A", "A", "B", "C"} you'll get [A, null, null]. There are numerous things that can be improved but the simplest modification of your code below. (I've changed only the second for loop) public String[] killDuplicate(String[] a) { String temp = ""; int counter = 0, counter2 = 0; for (int i = 0; i < a.length; i++) { if (!a[i].equals(temp))

Categories : Java

How to check if Java 7 version is installed via Cocoa?
Although you may have installed Java 7, you should have installed the Apple's Java Mac OS X 2012-006 update before. Having done that (and then installed java 7 again), java -version should tell you java version "1.7.x..." Determining the Default Version of the JDK

Categories : Java

Check java version during program load
You can use System.getProperty: System.out.println(System.getProperty("java.version")); 1.7.0_21

Categories : Java

PHP comparing strings with strings stored in variables
Verify the value returned by getcwd() From http://www.php.net/ getcwd Returns the current working directory on success, or FALSE on failure. On some Unix variants, getcwd() will return FALSE if any one of the parent directories does not have the readable or search mode set, even if the current directory does. See chmod() for more information on modes and permissions. http://www.php.net/manual/en/function.getcwd.php

Categories : PHP

Comparing numbers in bash
In bash, you should do your check in arithmetic context: if (( a > b )); then ... fi For POSIX shells that don't support (()), you can use -lt and -gt. if [ "$a" -gt "$b" ]; then ... fi You can get a full list of comparison operators with help test.

Categories : Bash

Comparing strings in R
You can use regmatches and gregexpr, but your question is somewhat vague at the moment, so I'm not positive that this is what you're looking for: > regmatches(a, gregexpr(b, a)) [[1]] [1] "7250" > regmatches(a, gregexpr(b, a), invert=TRUE) [[1]] [1] "6250;" ";6251" Based on your updated question, you're probably looking for grepl. > grepl(b, a) [1] TRUE > grepl(999, a) [1] FALSE ^^ We're essentially saying "look for 'b' in 'a'".

Categories : String

Check jQuery version and load a newer version
Bad idea to do what you are doing. If you really insist on having different jquery versions, you can always write some sort of a script manager. Basically you specify in your page's "config" what jquery versions are required on this page and the manager will load the appropriate one. Something like: // each page content before everything else Manager.reguire("plugin 1", "1.4.7"); Manager.require("plugin 2", "1.4.4"); // Main layout <head section> Manager.LoadRequiredVersions(); And the manager would just request the files for you, but don't forget that you might have to do some clever no-conflict stuff with jQuery if you want more than one on a single page. http://stackoverflow.com/a/1566644/486780 If it's one version per page then a manager would be the easiest option.

Categories : Javascript

Comparing two version numbers
Sample Code : NSString* v1 = @"3.1.1"; NSString* v2 = @"3.1.2.5.4"; if ([v1 compare:v2 options:NSNumericSearch] == NSOrderedDescending) { NSLog(@"%@ is greater than %@",v1,v2); } From the Apple Documentation for Comparing and sorting strings.

Categories : IOS

Comparing two strings using known algortihms
First of all you should preprocess your strings, I mean you should remove "a, the, as, an" and all common verbs, numnbers,... from input strings, also you should convert every plural form to the singular form, .... to unify all words. Then you can apply some string matching algorithms, or just put the words into the hashmap, or if they are a lot, put them into the trie, and run your similarity algorithm.

Categories : Java

Python: Comparing two strings that should be the same but that are not
It's likely that extra spacing is your culprit. You may also try downcasing the string. SentenceIMLookingfor='blha blha blah' with open('textfile.lua','r') as my_file: for line in my_file: if line.lower().strip() == SentenceIMLookingfor: #DO_SOMETHING If, however, you are not checking for a line that is exactly equal to the Sentence you're looking for, you'll want to use the in operator to check for equality, so replace the if above with if SentenceIMLookingfor in line.lower(): # you may not want .lower() Since there is no need to read the entire file into memory, you can iterate over the lines of the file with for line in my_file. .lower() converts a string to all lower-case letters, .strip() cuts off any preceding or trailing whitespace As sugge

Categories : Python

Comparing character strings in R
Here is an answer assuming your x's are in a list. If not first make one: my.vars <- list(x1, x2, ..., x25) corpus <- unique(unlist(my.vars)) occurences <- sapply(X=corpus, FUN=function (k) { occurences <- sapply(my.vars, function (l) k %in% l) occurences <- sum(occurences) }) names(occurences) <- corpus i.want <- occurences[occurences >= 5]

Categories : R

Comparing two strings in python?
You can try something like: sum(c1 != c2 for c1,c2 in zip(w1,w2)) zip(w1,w2) creates a generator that returns tuples consisting of corresponding letters of w1 and w2. i.e.: >>> list(zip(w1,w2)) [('h', 'j'), ('e', 'e'), ('l', 'l'), ('l', 'l'), ('o', 'y')] We iterate over these tuples (c1 gets assigned to each first char and c2 to each second char) and check if c1 != c2. We add up all the instances for which this condition is satisfied to arrive at out answer. (See zip() and sum()) >>> w1 = 'hello' >>> w2 = 'jelly' >>> >>> sum(c1 != c2 for c1,c2 in zip(w1,w2)) 2

Categories : Python

Comparing two strings with different orders
Try this instead:: if(stringWithPipes.Any(P => P.split('|') .All(K => "beginning|middle2|middle|end".split('|') .contains(K))) Hope this will help !!

Categories : C#

Problems comparing strings within an iterator
OGNL interprets a single character within single quotes as a char, not a String. Use double-quotes: <s:if test='top.equals("_")'> See Why won't the 'if' tag evaluate a one char string for details.

Categories : String

conditional OR never works when comparing two strings
You want to check if it not Pennsylvania and if it is not New York so you have to use && (AND) not || (OR); foreach (DataRow row in uwDataTable.Rows) { if ((row[15].ToString() != "New York") && (row[15].ToString() != "Pennsylvania")) { rowsToDelete.Add(row); } }

Categories : C#

Comparing strings containing IPv4 addresses in C
You can try the sexy way, store all values in one unsigned integer and compare it. const char* ip1 = "192.168.145.123"; const char* ip2 = "172.167.234.120"; unsigned char s1, s2, s3, s4; unsigned int uip1, uip2; sscanf(ip1,"%hhu.%hhu.%hhu.%hhu",&s1,&s2,&s3,&s4); uip1 = (s1<<24) | (s2<<16) | (s3<<8) | s4; //store all values in 32bits unsigned int sscanf(ip2,"%hhu.%hhu.%hhu.%hhu",&s1,&s2,&s3,&s4); uip2 = (s1<<24) | (s2<<16) | (s3<<8) | s4; if (uip1 > uip2) { printf("ip1 greater !"); } else { printf("ip2 greater or equal !"); }

Categories : C

Comparing 2 strings, one from file and one declared
The file read includes the , so you have to remove it: $str2 = $_; chomp $str2; And, if your file has only one line, replace the while loop by: $str2 = <FILE>; chomp $str2;

Categories : Perl

Ignore numbers while comparing strings
You can use all(): >>> one = "addf.0987.addf" >>> two = "addf.1222.addf" >>> all(i[0] == i[1] for i in zip(one, two) if not i[0].isdigit()) True Or: >>> one = "addf.0987.addf" >>> two = "addf.1222.addf" >>> [i for i in one if not i.isdigit()] == [i for i in two if not i.isdigit()] True

Categories : Python

Comparing Strings in IF( statement in php issue
Try this: $day = date("Y-m-d"); //get rid of the (string) cast $thedate = date("Y-m-d", strtotime($thedate)); if($day == $thedate) { ... // your stuff } else { echo ('They do not match.'); } There may be some minute differences in the way the string is encoded/stored. Since your $day variable was created with the date() function, you stand a better chance of matching them properly by doing the same with $thedate.

Categories : PHP

Regex for comparing Strings with spaces
You can make the spaces optional using a zero-or-one quantifier (?): (?!My ?disk1$|My ?Disk2$) This assertion will reject substrings like MyDisk2 or My Disk2. Or to handle potentially many spaces, use a zero-or-more quantifier (*): (?!My *disk1$|My *Disk2$) Note that if you're running this in an engine which ignores whitespace in the pattern you may need to use a character class, like this: (?!My[ ]*disk1$|My[ ]*Disk2$) Or to handle spaces or underscores: (?!My[ _]*disk1$|My[ _]*Disk2$) Unfortunately if the spaces can be anywhere in the string, (but you still care about matching the other letters in order), you'd have to do something like this: (?! *M *y *d *i *s *k *1$| *M *y *D *i *s *k *2$) Or to handle spaces or underscores: (?![ _]*M[ _]*y[ _]*d[ _]*i[ _]*s[ _]*k[ _]*1

Categories : Regex

C++ comparing a string with an array of strings
With find: #include <algorithm> #include <iterator> auto it = std::find(std::begin(food), std::end(food), word); if (it != std::end(food)) { // found *it } else { // not found }

Categories : C++

Error comparing strings in Cocos2d-x
You could use c++ specific function for that. http://www.cplusplus.com/reference/string/string/compare/ If that doesn't work char * cstr = new char [str.length()+1]; std::strcpy (cstr, str.c_str()); and then compare it.

Categories : Android

comparing strings and calculating occurance
Depending on your description, I got import math v1 = [['be', 'VSIS3S0', 1], ['scott', 'NP00000', 2], ['north', 'NCMS000', 1], ['revolution', 'NP00000', 1], ['name', 'VMP00SM', 1]] v2 = [['mechanic', 'NCMS000', 1], ['be', 'VSIS3S0', 1], ['tool', 'AQ0CS0', 1], ['sam', 'NP00000', 1], ['frida', 'NP00000', 1]] v3 = [['be', 'VSIP3S0', 1], ['scott', 'NP00000', 1], ['who', 'NP00000', 1]] v = [v1,v2,v3] countdict = {} for vi in v: for e in vi: countdict[e[0]] = countdict.get(e[0],0) + 1 scoredict = {} for vi in v: for e in vi: scoredict[e[0]] = scoredict.get(e[0],0) + (e[2] * math.log10(3.0/countdict[e[0]])) print scoredict I save the output as a dict, which is: {'be': 0.0, 'revolution': 0.47712125471966244, 'north': 0.47712125471966244, 'name': 0.47712125471966244

Categories : Python

How do I check which version of groovy is with which version of grails
You can use the grails shell to launch an interactive Groovy console within Grails and identify the version. $ grails shell Groovy Shell (2.0.8, JVM: 1.7.0_21) Type 'help' or 'h' for help. ----------------------------------- groovy:000>

Categories : Grails

Comparing strings in a JDO query fails when value contains a "Comma"
So you're calling industryNameExists("Architecture, Engineering, and Drafting") and trying to match a JDO with industryName exactly equal "Architecture, Engineering, and Drafting"? Assuming you don't have any typo or space difference the only thing suspect is the getBytes(). Try the following: Query q = pm.newQuery(Industry.class, "this.industryName == :industryNameParam"); List<Industry> industry = (List<Industry>) q.execute(industryName); You can also try variation filters like "this.industryName.equalsIgnoreCase(:industryNameParam)" and "this.industryName.startWith(:industryNameParam)" to troubleshoot. If it still does not work, try logging the SQL generated for review and compare with a hand-written query that works.

Categories : Google App Engine

C++: Spaces in strings prevent me from comparing cin input.
Use std::getline(std::cin, cookieType) in the while loop. operator>> will stop at the very first space while std::getline by default stops at the newline. It looks like you have characters left in the input stream. Add the following line before the first call to std::getline (and include <limits> header): std::cin.ignore(std::numeric_limits<std::streamsize>::max(), ' ');

Categories : C++

Logical error in comparing two strings in Python
If the condition is true, the code in the if statement absolutely will execute. You can be certain about that. Therefore, the condition simply must not be true. Without knowing exactly what your data looks like it's impossible to know for certain. Most likely the values look identical, but they simply cannot be. So, start with the premise that the values are not equal, and answer the question "if they aren't equal, why aren't they equal?". For example, you can print out the type of each variable, the length of each variable, or you could write a little function that compares each byte one at a time to see which one is different. There's likely either an invisible character you aren't seeing visually (perhaps a leading or trailing space, or perhaps a control character such as a carriage re

Categories : Python

codeigniter database select comparing strings
You do not escape the string ($nomes_frasesr_cee[$j]) and that probably leads to an invalid statement. In order to create a statement that is valid try this: $query1 = $this->db->query("SELECT * FROM frases_r where cod_frase_r=?;", array($nomes_frasesr_cee[$j]));

Categories : PHP

Comparing two strings with special characters via charCodeAt
A string is a sequence of bytes. As such, it cannot be rendered as anything except as bit pattern. Next, a character set comes into play. Here, you map numbers to characters, for example 65 to A, 97 to a and 228 to ä. Finally, you need a character encoding, which maps the number to a bit pattern. For number 228, the usual 8-bit encoding simply uses 0xE4 as bit pattern. UTF-8 encoding will use 0xC3 0xA4 as bit pattern and UTF-16 will use 0x00 0xE4 as bit pattern. So in order to properly compare a string, you need to know its bit pattern (byte sequence), its encoding and its character set. If you lack any, strings cannot be properly compared. Nowadays, Unicode is used as character set most of the time. If you only use the very basic characters, ASCII will do the job as well. ASCII is a s

Categories : Javascript

How to avoid comparing duplicate strings in a list
Use itertools.combinations(): >>> string_list = ["PII", "AZO", "CVCO", "MOD"] >>> from itertools import combinations >>> for a, b in combinations(string_list, 2): ... print(a, b) ... PII AZO PII CVCO PII MOD AZO CVCO AZO MOD CVCO MOD Your version generated permutations instead.

Categories : Python

Back slash issue while comparing two strings
Backslash is used to represent special characters like " on a NSString literal. So, actually the str2 string doesn't have any backslash, while the summary string do (added by stringByReplacingOccurrencesOfString:withString:).

Categories : Iphone

Joining and comparing a large number of input files from bash
You are almost there. You have misplaced the spaces in the if block. It should be like this: if [[ "$A1" = "$B1" && "$A1" = "$C1" ]];then Note that there is no space between the opening brackets, and there is a space before the closing ones. Also you have some typos in your test files. In a.txt you should change klm.nop=789 to kml.nop=789 And in c.txt you should change abca.def=12344 to abc.def=12344

Categories : Bash

Batch File - Comparing strings as integers not working
The problem is DELAYED EXPANSION. When the for ...%%a... is parsed, the value of currentversion as it stands at that time is substituted into the code. Use !currentversion! to obtain the RUN-TIME value (with delayedexpansion invoked, as you have...) (Also: to assign a value, use SET VAR=VALUE not SET %VAR=VALUE)

Categories : Batch File

Comparing user input unicode strings in Python 2.7
Your current approach isn't bad, but you should probably use unicodedata.normalize() for the comparison. The docs linked above explain why this is a good idea. For example, try evaluating the following: u'Ç' == u'Ç' Spoiler alert, this will give you False because the left side is the sequence U+0043 (LATIN CAPITAL LETTER C) U+0327 (COMBINING CEDILLA), and the right side is the single character U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA). You can use unicodedata.normalize() to handle this properly by first converting the strings to a normalized form. For example: # -*- coding: utf-8 -*- from unicodedata import normalize from __future__ import unicode_literals user_input = normalize('NFC', raw_input("Please, write árido: ").decode("utf8")) if normalize('NFC', u"árido") == use

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.