w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
scala pattern matching nested cases
The problem you are hitting is that your example input (val x1 = 1) doesn't match the one case you gave (since x1 is not greater than 1). You will need to either modify your existing case (eg. change the if to something like if(x >= 1)) or add at least one more case, and should probably consider a default case. eg.: val str = x1 match { // scala.MatchError: 1 (of class java.lang.Integer) case x if(x > 1) => "x"+x match {case "x1" => "yes"} case _ => "no match" }

Categories : Scala

Performance Differences of Nested If Else Statements vs. ElseIf Statements
It depends on your code. The if statement is only accessed when a condition is met, otherwise it is ignored. the if elseif else block is the same but it is testing for many conditions and depending on which one is met a different action might have to be performed in order to get the results u want. My opinion is "It depends upon cases". If you want to execute everything in your code,then use elseif.. if you want to ignore something use if..

Categories : Dotnet

if statements, with x^2 possbilities, matching to a response, optional fields
Get your $a, $b etc. thingies in an array somehow; I suppose they're originally submitted as an array. So let's suppose you have an array like: $letters = array('a', 'c'); Then simply: $result = array_combine($letters, array_slice($response, 0, count($letters)));

Categories : PHP

Matching a Pattern in PHP
Try with substr like $needle = 'BA700'; $haystack = 'BA70012345'; if(substr($haystack, 0, 4) == $needle) { echo "Valid"; } else { echo "In Valid"; } You can also check regards with the case by changing both of them in either UPPER or LOWER like if(strtoupper(substr($haystack, 0, 4)) == $needle) { echo "Valid"; } else { echo "In Valid"; }

Categories : PHP

Pattern Matching in R
Here's one approach using term.count (a non exported function) from the qdap package: lst <- list(c('a', 'b', 'c', 'd', 'b', 'c'),c('b', 'c', 'e')) lst2 <- lapply(lst, paste, collapse="") #use lapply to paste the list ## install.packages("qdap") sapply(lst2, qdap:::term.count, "bc") #count occurences ## > sapply(lst2, qdap:::term.count, "bc") ## bc bc ## 2 1 If you don't want to use qdap look at the source for term.count and take what you need.

Categories : R

Pattern Matching on Either
try this one trait Either[+E, +A] { def map[B](f: A => B): Either[E, B] = this match { case Right(y) => Right(f(y)) case left: Left[E] => left } }

Categories : Scala

Nested For Each statements
I would suggest firstly that you read the two columns into an array. dim myarray() as variant myarray = range("A2:E" & lastrow).value2 Then loop through the column E values, looking for blanks: n = 2 cb_project = myarray(n,1) do while n <= lastrow 'copy row matching cb_project if myarray(n,5) = "" then cb_project = myarray(n+1,1) else 'copy row matching myarray(n,5) endif n=n+1 loop

Categories : Excel

Asterisk pattern matching
I think pattern matching can be done with other languages like java,PHP. Asteriks support these languages. Here is a tutorial for asterisk-java http://www.asterisk-java.org/development/tutorial.html I think it can be done with AMI.

Categories : Regex

Matching a Specific URL Pattern with PHP
Replace (.*) with (.*?) - use lazy quantification: preg_match('/<a href="https://docs.google.com/file/d/(.*?)</a>/', $file, $matches);

Categories : PHP

Pattern Matching in perl
Not very nice, but the next: use strict; use warnings; while(<DATA>) { chomp; next if /^s*$/; my @parts = split(/_/); my $b = pop @parts if $parts[$#parts] =~ /d/; $b //= '"original"'; my $a = join('_', @parts); print "$a = $a and $b = $b, "; } __DATA__ Rita_bike_house_Sha9 Rita_bike_house prints: $a = Rita_bike_house and $b = Sha9, $a = Rita_bike_house and $b = "original",

Categories : Perl

pattern matching in arrays
The following regexp checks, whether the string begins with http://www.facebook.com/ or https://www.facebook.com/: '#^https?://www.facebook.com/#i' So, probably, your code should look like this: array('match', true, '#^https?://www.facebook.com/#i'))

Categories : PHP

F# pattern matching oddity
I think F# compiler is being practical in this case. In the end, the second rule can be expressed as a constraint on input list xs: xs = hd :: tl && xs = l F# compiler doesn't seem to explore && constraints. This is reasonable because constraints can be arbitrarily complex and the use of & is quite rare. We have a similar problem with partial active patterns: let (|Empty|_|) = function | [] -> Some() | _ -> None let (|NonEmpty|_|) = function | _ :: _ -> Some() | _ -> None // warning FS0025 let f = function | Empty -> "Empty list" | NonEmpty -> "Not so empty list" To fix this issue, you can: Use as instead of &, which is more appropriate since l is just a binding. Add a wildcard pattern to the end to eliminate th

Categories : F#

Concatenating and Pattern Matching SQL
Are you after something like this: SELECT `c`.`user_id`, `c`.`zip`, `a`.`city`, CONCAT_WS( ';', `c`.`city`, `aa`.`city-state` ) AS `location` FROM `Accounts` AS `a` LEFT JOIN `Addr` AS `aa` ON `aa`.`zip`, `a`.`id` LEFT JOIN `Customer` AS `c` ON `c`.`user id`, `a`.`id`

Categories : SQL

F# odd pattern matching issues
The match statement doesn't work like you think it does - the correct syntax is match i with | t when t = bs.Length In the second case, you actually create a new variable called bsLength which hides the definition of the earlier bsLength and matches all integers, so you get the rule never matched warning.

Categories : F#

Having issues in matching pattern
purely based on the example. seems like a termination line problem + SO's 4 spaces quotes.. /<div id="right_song">[ ]+<div style="font-size:15px;"><b>([^<]*)</b></div>[ ]+<div style="clear:both;"></div>[ ]+<div style="float:left;">[ ]+<div style="float:left; height:27px; font-size:13px; padding-top:2px;">[ ]+<div style="float:left;"><a href="([^"]*)" rel="nofollow" target="_blank" style="color:green;">Download</a>/ however there's a shorter/safer way of grep'ing patterns which allows for the 3rd party to change subtle css details /<div[^>]+>[ ]+<div[^>]+><b>([^<]*)</b></div>[ ]+<div[^>]+></div>[ ]+<div[^>]+>[ ]+<div[^>

Categories : Android

Pattern matching within a string
As alternative, use a for loop and break after first iteration: shopt -s nullglob for f in /tmp/foo-*; do echo "Configure with --with-foo="$f"" break done

Categories : Bash

Pattern Matching on GADTs
Cast :: (Castable a b) => Expr a -> Expr b So here: instance (Show a) => Show (Expr a) where show (Cast e) = "Cast " ++ show e -- ERROR Cast e is of type Expr a. We have a Show a constraint, and by this very instance that implies Show (Expr a), so we can call show on things of type Expr a. But e is not of type Expr a. Cast takes an argument of any type Expr a1 and gives you an Expr a (renaming the type variables to stay consistent with what we're talking about in the instance), so e is of type Expr a1. We don't have a Show constraint for the type a1, and we require Show a1 to imply Show (Expr a1), so there's no way to show e. And there's no way to add such a constraint in the Show instance, because the type a1 doesn't appear in the type of Cast e. That seems to be the who

Categories : Haskell

Pattern Matching and Replacement
What about replace function? Function replace(string text, from text, to text) Description Replace all occurrences in string of substring from with substring to Sample replace('abcdefabcdef', 'cd', 'XX') abXXefabXXef For your code is a simple update: Update table T set text_col = replace( text_col, 'pear', 'watermelon' ); Updated due Igor Romanchenko suggestion: Update table T set text_col = replace( text_col, 'pear', 'watermelon' ) where text_col like '%pear%';

Categories : SQL

Pattern matching in html
You cannot open multiple tabs. There's no concept of tab in standard DOM.Its more of a browser thing I have tried this and there is no way you can do this. However,the nearest you can come is use these properties in the same function window.location.href which opens in the same tab and window.open which opens in a new tab. http://jsfiddle.net/Jx433/

Categories : Javascript

nested FOREACH statements
For fastest execution a UDF would be best. In pure Apache Pig it would be nice if you could do count on (group, lt, ln) before creating a relation with your schema. It woul be something like this (it is just a pseudo script, might need some debugging) Assuming load schema is (id, lt, ln) inpt = LOAD ....... as (id, lt : chararray, ln : chararray); grp1 = GROUP inpt BY (id, lt, ln); data1 = FOREACH grp FLATTEN(inpt), COUNT(data1) as cnt; data2 = GROUP data_wtih_count BY id; --data2: {group: chararray,data1: {(id, lt: chararray,ln: chararray, cnt : int)}} most_probable_pair = FOREACH data2 { ord = ORDER data1 BY cnt ASC; top = LIMIT ord 1; GENERATE group, top.(ln, lt); } Or you could flatten data2 and data1 and start with grp1.

Categories : Apache

Nested If Statements in SSRS
Let's dissect your statement: =SUM( IIF(UCASE(TRIM(Fields!UOP.Value))="Y", IIF(UCASE(TRIM(Fields!HED.Value))="Y", IIF(UCASE(TRIM(Fields!FROMB.Value))="RED", IIF(UCASE(TRIM(Fields!TOB.Value))="BLUE", 1, 0), 0), 0) ) Your parentheses are unbalanced, and you are missing the false argument for the first IIF. Alternatively, you can invert your conditions and use SWITCH instead, which would be a bit easier to read: =SUM(Switch( _ UCASE(TRIM(Fields!UOP.Value))<>"Y", UOPFalseValue, _ UCASE(TRIM(Fields!HED.Value))<>"Y", 0, _ UCASE(TRIM(Fields!FROMB.Value))<>"RED", 0, _ UCASE(TRIM(Fields!TOB.Value))<>"BLUE", 0, _ True, 1)) Or, since it appears yo

Categories : Reporting Services

Ruby: nested if statements
I would do something like the following as it makes it clear that each case is mutually exclusive: def hours_occupied(date) if availability = get_work_hours(date) focus = "work" elsif availability = get_family_hours(date) focus = "family" elsif availability = get_friend_hours(date) focus = "friends" end end

Categories : Ruby

Can if statements be nested in a while loop?
Check your code here you are missing else block: userInput = input.nextLine(); if ( !userInput.equalsIgnoreCase(endProgram) ) { System.out.printf("You entered the following: %s", userInput); } else This is the reason for the compilation error. You can fix this by either removing the else altogether or if you want to add something in it then do the following: userInput = input.nextLine(); if ( !userInput.equalsIgnoreCase(endProgram) ) { System.out.printf("You entered the following: %s", userInput); } else { // Do something } And to answer your questions, yes it's perfectly valid to nest if statements in a while loop.

Categories : Java

Walking Through Nested For statements
The first one enumerates the range from zero to the value of entries_per_column as a variable named row For each row, there is an enumeration from zero to the value of width as a variable named column So this is creating a two dimensional matrix - should be pretty digestible. For each column in a row, the value in that space is assigned to the variable entry. If the entry does not exceed the maximum value of the matrix, then it is put inside the return list ret as a list. After this ret is given a newline character so that a new row can be created visually (when ret is printed out). So this program makes a list, ret, which contains a two dimensional matrix of values - a number of lists that are rows, each of which contain some single-valued lists called columns, which have entries insid

Categories : Python

"set ic" command in vim results in non matching of pattern
try :set scs? to see have you enable the smartcase mode, if so, it will override ignorecase setting when you input upper case word For more info, type :h smartcase

Categories : Vim

F# - Pattern Matching on boxed tuples
let coerceColor a = match box a with | :? Color as c -> c | :? (int*int*int) as t -> t |> Color.FromArgb | _ -> failwith "Cannot coerce color" But if I could change the design, I would rather use a DU or alternatively a static member with overloads.

Categories : F#

pattern matching using "LIKE" in query ,postgres
You want to use the underscore instead of the percent character. Underscore _ matches a single character, where as percent % matches zero or more characters. select 'R011' like 'R01_' # true select 'R01' like 'R01_' # false Or better yet you can use regular expressions to match just decimal characters. select 'R011' ~ 'R\d{3}' http://www.postgresql.org/docs/9.2/static/functions-matching.html

Categories : Postgresql

White space pattern matching using sed
If I understand correctly, you have name="blah" value="blah" on seperate lines, and want to just remove the sed ':a;N;$!ba;s/ / /g' would do what you want taken from SED: How can I replace a newline ( )?

Categories : Bash

How to apply pattern matching in this case
Not a pattern matching, but should do the trick: checkTop(clickedIndex) orElse checkBottom(clickedIndex) orElse checkLeft(clickedIndex) orElse checkRight(clickedIndex) orElse is a method defined for Option. When option is defined, it returns an option itself, otherwise it tries an alternative.

Categories : Scala

Pattern matching for character and end of line
The $ means end-of-line. Thus this should work: Pattern pattern = Pattern.compile("(?<=Hello:).*?(?=,|$)"); So you look-ahead for a comma or the end-of-line. Test.

Categories : Java

Z3 - Formalising an array pattern matching
I get the feeling that you deactivated both MBQI and AUTO_CONFIG, as done in this variant of your code. There, you get an unknown for the first check-sat and an unsat for the second. If you comment both set-options, you'll get sat and unsat. The unsat is expected because the assertions made inside the push/pop scope contradict your first axiom. Regarding the unknown vs sat I have to speculate a bit. According to my understanding, MBQI tries to find an interpretation for all uninterpreted symbols, that is, it tries to find a model, such that the given assertions can be satisfied. Without MBQI, Z3 relies on E-matching, that is, it does not try to find an interpretation for uninterpreted symbols. Z3 does try to find a contradiction, but the assertions made up to the point of the first che

Categories : Arrays

PHP preg_replace is not matching entire pattern
You should use this regex /(?<=||)[a-zA-Z]{4,8}$/ You need to escape | since it represents OR in regex $ marks the end of string (?<=||) is a zero width lookbehind

Categories : Regex

boost mpl sequence pattern matching
Wow, I find the root of the problem. Look at the error message(you could see it if you comment typedef get_first<SEQ_C> type; line): error: ‘type’ in ‘struct get_first<boost::mpl::vector_c<int, 1l, 2l, 3l> >’ does not name a type // ^ ^ ^ As you can see, g++ interprets passed arguments as long, not as int. So, if you change your specification to: template<template<class T, long... S> class SEQ_C, class T, long x, long... xs> struct get_first<SEQ_C<T, x, xs...>> { enum { value = x }; typedef get_first<SEQ_C<T, x, xs...>> type; }; It would work. Of course, it is not a solution, I just show, how it would work. I think, it's bug in g++, since clang++ prod

Categories : C++

pattern matching an array without redundancies
In your case I'd just double up the match (though one could also write a custom extractor) and to avoid duplication return a function that does the work: def badLine() = throw new IllegalArgumentException("unable to identify line format") lineSplit match { case Array(cls @ TaggedString(), prop @ TaggedString(), x, ".") => val processValue = x match { case value: Literal() => () => processLiteral(value) case value: LiteralwithSchema() ... ... case _ => badLine() } processProperty(prop) processValue() case _ => badLine() }

Categories : Scala

Pattern matching filtering in slickGrid
As it was mentioned, your question is really unclear!!! Though I'm not sure if you are looking for conditional filters (>, >=, etc..) is that what you are intending to do? If that is what you are looking for then I would suggest you read my answers from these previous post here: SlickGird header row multi filter and here SlickGrid column type

Categories : Javascript

Is this "string pattern matching" algorithm? Or something else?
I don't have a direct answer to your question, but after thinking about it there's several ways in which I could frame the problem: Document retrieval (such as used in search engines -- how do they rank disjunctive queries so quickly?) Non-metric nearest neighbor (link is for the common metric version) 0-1 linear programming As such, I don't think there's one term for this problem -- it's too interesting to too many fields. There's certainly plenty of studies between the three fields (e.g. Google): Document retrieval Non-metric nearest neighbor 0-1 linear programming

Categories : String

Pattern matching doesn't work
Because List(x) only matches lists with one element. So def example(list: List[Int]) = list match { case Nil => println("Nil") case List(x) => println(x) } only works with lists of zero or one element.

Categories : Scala

preg_match pattern-matching expression to get URL in php
if (preg_match('/(s?(www.w+.com)s?)/', $text, $matches)){ $var = $matches[1]; } That assumes .com. If you want to allow, for example, .net and .org, you can modify it as: if (preg_match('/(s?(www.w+.(com|net|org))s?)/', $text, $matches)){ $var = $matches[1]; }

Categories : PHP

Find last column matching pattern in each row
Just use the apply function along the axis=1 and pass the pattern parameter as an additional argument to the function. In [3]: def func(row, pattern): referrer = np.nan for key in row.index: if row[key] == pattern: referrer = key return referrer df['last_referred'] = df.apply(func, pattern='referred', axis=1) df Out[3]: name action_1 action_2 action_3 last_referred 0 bill referred referred None action_2 1 bob introduced referred referred action_3 2 mary introduced NaN 3 june introduced referred action_2 4 dale referred action_1 5 donna i

Categories : Python

Writing a pattern matching macro
The following seems to work, or at least compile: val cases = subs.toList.map { sub => val pat = Bind(newTermName("x"), Typed(Ident("_"), Ident(sub.asClass))) val body = reify(???).tree // TODO CaseDef(pat, body) }

Categories : Scala



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