w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

Removing given range of letters from a sequence
First of all, always use use warnings; AND use strict;. use Data::Dumper; would really help you here. Also, you can remove the redundant -w (warnings) flag from your shebang line. > original files are much much larger and split may go out of memory You shouldn't read the whole file into memory: @array = <FH>; Instead you should go line by line: while (my $line = <$FH>) { Which brings us to another issue... You should use the 3-arg lexically scoped open. open my $fh, ">", $file; The next thing, @nums = split( / /, "@num"); has a few issues. lose the quotes around the variable. @nums is going to contain the number of lines, and that's it. So once you've fixed all this.... Your logic looks wrong with the foreach loops. Why are you hard-coding 4 values, whe

Categories : Perl

label a sequence of plots with letters using lapply
This is the an example of the downside of using lapply/sapply ... the names of list elements do not get passed to the function, only the values do. So you can get around that when using lapply by working with names(yourlist) (or perhaps 1:length(yourlist)) and pulling from 'yourlist' with : lapply(names(yourlist), function(x){ plot( yourlist[[x]] } ) In your case that does mean you will need to rewrite your function.

Categories : R

Perl - partial pattern matching in a sequence of letters
* is a quantifier and meta character. Inside a character class bracket [ .. ] it just means a literal asterisk. You are probably thinking of .* which is a wildcard followed by the quantifier. Matching entire string, e.g. "abaazt". /^ab.*zt$/ Note the anchors ^ and $, and the wildcard character . followed by the zero or more * quantifier. Match substrings inside another string, e.g. "a b abaazt c d" /abS*zt/ Using word boundary  to denote beginning and end instead of anchors. You can also be more specific: /(?<!S)abS*zt(?!S)/ Using a double negation to assert that no non-whitespace characters follow or precede the target text. It is also possible to use the substr function if (substr($string, 0, 2) eq "ab" and substr($string, -2) eq "zt") You mention that the string is

Categories : Perl

Why does [a-zA-Z] match both numbers and letters?
The regular expression is matching this substring of your test value: user/d. If you want to check against the whole string, add start (^) and end ($) anchors to your pattern: $pattern = '~^user/(:var)$~'; To check against the start/end of a string OR another delimiter such as /, it would look like this: $pattern = '~(?:^|/)user/(:var)(?:$|/)~'; This will force it to consider the entire value up until either the end of the string or the next /... preventing partial matches like you encountered in your question. (The ?: indicates a non-capturing group, which means that the extra () groups won't end up in your resulting list of matches) You'll also need to allow the [a-zA-Z] class to repeat with +, or it will only match single-character usernames: $pattern = str_replace('(:var)', '

Categories : PHP

How do you compare two strings in SQL and only get all of the letters that match?
I don't think that SQL is well suited to this problem, you could really do with a programming language where you can compare character by character. What database are you using, it may be an option to write a custom function to achieve what you want and allow the function to be called from within your SQL statement. UPDATE I believe that IBM DB2 offers a procedural extension which you could use to write customer functions as suggested above. Unfortunately, I do not have any experience with DB2 so I will not be able to help with this. I found the following link with some information for you: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/c0011916.htm

Categories : SQL

Regex to match only letters between two words
I guess you're looking for something like this: import re def equal_letters(x, y): return re.sub(r'W+', '', x) == re.sub(r'W+', '', y) >>> equal_letters("Ultramagnetic MC's", "Ultramagnetic MC’s") True >>> equal_letters("Ultramagnetic MC's", "Ultramagnetic Foo") False

Categories : Python

MySQL, sort single letters first, then double letters, then triple letters
For the data you have provided, you can just use the length: order by length(letters), letters; This assumes that the letters are as described in the question, with no additional letters afterwards. If these are prefixes, the brute force approach would be: order by ((substring(letters, 1, 1) = substring(letters, 2, 1)) + (substring(letters, 1, 1) = substring(letters, 3, 1) ), letters; That is, compare the initial character to the next two. The above returns 0, when the first and second characters are different; 1, when the first and second are the same but the third different; and 2 for three character prefixes.

Categories : Mysql

MySQL RegExp how to match all given letters in any position
txa|tax|axt|atx|xta|xat Edit live on Debuggex Honestly, you can probably do it without "hard coding" it. However, the regex will prob be longer then this because there isn't many permutations of tax. ^(?=.*[t])(?=.*[x])(?=.*[a])[tax]{3}$ Edit live on Debuggex This is the actual not "hardcoded" way.

Categories : Mysql

How to match sequence group?
If you're still looking for PHP code. function getSequence($str) { $prev = 0; $next = 0; $length = strlen($str); $temp = ""; for($i = 0; $i < $length; $i++) { $next = ord($str[$i]); if ($next == $prev + 1) { $temp .= $str[$i]; } else { if (strlen($temp) > 1) $result[] = $temp; $temp = $str[$i]; } $prev = $next; } if (strlen($temp) > 1) $result[] = $temp; return $result; } $str = "abcwhateverdefwhatever34567whatever012"; print_r(getSequence($str));

Categories : Regex

How to match a sequence in a List with Linq?
There is another question that has a working answer; LINQ: Check whether an Array is a subset of another bool isSubest = !childList1.Except(masterList).Any(); will do it for you. You could also do if (childList1.Except(masterList).Count > 0) // items in child not in master else //child is a subest of master

Categories : C#

Regex to match only one character sequence within string
What you want is called a non-capturing group. There are already some fairly high-quality examples of doing this in Java on SO - for example, this question: Non capturing group?

Categories : Java

Hash function which returns not just lowercase letters and numbers, but also symbols and uppercase letters
You seem to refer to the hexdecimal-ascii representation ("letters and numbers") of the hash. That's just a different way of saying "number", only with sixteen symbols instead of ten as in decimal or two in case of binary. You can map the hash - which is just a number like any other - to any representation you want. You may, for example, base85-encode the hash which gives you a ascii-string like ">uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>", depending on the size of the hash.

Categories : PHP

Algorithm and Data Structure for Checking letters in a word with another set of letters
This is for something like Scrabble or Boggle, right? Well, what you do is pre-generate your dictionary by sorting the letters in each word. So, word becomes dorw. Then you shove all these into a Trie data structure. So, in your Trie, the sequence dorw would point to the value word. [Note that because we sorted the words, they lose their uniqueness, so one sorted word can point to multiple different words. ie your Trie needs to store a list or array at its data nodes] You can save this structure out if you need to load it quickly later without all the sorting steps. What you then do is take your input letters and you sort them too. You then start walking through your Trie recursively. If the current letter matches an existing path in the Trie, you follow it. Because you can have

Categories : Java

ObjC / iOS - Capitalize first letters of each word without modifying other letters
Try this - (NSString *)capitilizeEachWord:(NSString *)sentence { NSArray *words = [sentence componentsSeparatedByString:@" "]; NSMutableArray *newWords = [NSMutableArray array]; for (NSString *word in words) { if (word.length > 0) { NSString *capitilizedWord = [[[word substringToIndex:1] uppercaseString] stringByAppendingString:[word substringFromIndex:1]]; [newWords addObject:capitilizedWord]; } } return [newWords componentsJoinedByString:@" "]; }

Categories : IOS

How to convert roman-latin letters into Japanese letters?
public class Converter { public String RomajiToHiragana(String wordRomaji) { wordRomaji = wordRomaji.toLowerCase(); // Seion if (wordRomaji.contains("kya")) { wordRomaji = wordRomaji.replace("kya", "きゃ"); } if (wordRomaji.contains("kyu")) { wordRomaji = wordRomaji.replace("kyu", "きゅ"); } if (wordRomaji.contains("kyo")) { wordRomaji = wordRomaji.replace("kyo", "きょ"); } if (wordRomaji.contains("sha")) { wordRomaji = wordRomaji.replace("sha", "しゃ"); } if (wordRomaji.contains("shu")) { wordRomaji = wordRomaji.replace("shu", "しゅ"); } if (wordRomaji.contains("sho")) { wordRomaji = wordRomaji.replace("sho", "しょ"); } if (wordRomaji.contains("cha")) { wordRomaj

Categories : Android

Convert special letters to ascii letters in java
Generally speaking, ASCII is very poor and old character table and it actually doesn't contain wanted characters. But what about your issue, it isn't related to ASCII table. Java works with unicode. Just what you need is include such symbols into your regexp, something like [^a-zA-Z0-9äàèçîñö]. The core problem is that such regular constructions as a-z or A-Z (called symbol classes) don't include such special national symbols. You have to include them manually.

Categories : Java

Removing letters from a list of both numbers and letters
You can use str.translate to filter out letters: >>> from string import letters >>> strs = "6483A2" >>> strs.translate(None, letters) '64832' There's no need to convert a string to a list, you can iterate over the string itself. Using str.join, str.isdigit and list comprehension: >>> ''.join([c for c in strs if c.isdigit()]) '64832' or this as you want the sum of digits: sum(int(c) for c in strs if c.isdigit()) Timing comparisons: Tiny string: >>> strs = "6483A2" >>> %timeit sum(int(c) for c in strs.translate(None, letters)) 100000 loops, best of 3: 9.19 us per loop >>> %timeit sum(int(c) for c in strs if c.isdigit()) 100000 loops, best of 3: 10.1 us per loop Large string: >>> strs = "6483A2"*1000 >&g

Categories : Python

Screen readers: How to make a word with tags surrounding its letters be spoken as a single word, rather than a series of letters?
This not a solution but it might be an useful workaround if your situation allow you. I felt you want to wrap one letter to render that differently, instead you can show the word "test" as an image by doing so you can create it any way you want and put the word "test" as alt attribute in image <h1>This is a <span id="specialWord" ><img src = "testImage.jpg" alt = "test"></span>. </h1> So if it is like that OS X voice over will read it properly. Because if I remember correctly it reads the alt attribute of an image. Now in that case a problem might arise. Anybody want to select it as a text then it would not be possible. You can solve that by calling a javascript function to dynamically change the inner html of the span tag (with id="specialWord" ) to "

Categories : HTML

How to generate sequence id and move table rows up or down and dynamically adjusting each row's sequence ID?
you can do this: $('#add').on("click", function(){ var clone=$('#one tbody input:checked').parent().parent().clone(); clone.each(function(){ $(this).appendTo("#two tbody").attr("id",$(this).index()); }); return false; }); $('#remove').on("click", function(){ $('#two tbody input:checked').parent().parent().remove(); $('#two tbody tr').each(function(){ $(this).attr("id",$(this).index()); }); return false; }); $(".up,.down").click(function(){ var row = $('#two tbody input:checked').parent().parent(); if ($(this).is(".up")) { row.each(function(){ var previndex=$(this).prev().index(); if(previndex>=0){ v

Categories : Javascript

How to fill gaps in a sequence of integers, by choosing the best complementary sequence
Following steps will do it 1) Store the gaps of A, in an array. 2) Then Map each element of A With different B(B1,B2,..) 3) And then display the result, based on the result in the above step This is a brute force approach to solve this problem.

Categories : Algorithm

Microsoft SQL Server 2012 Sequence Not Working - keeps incrementing sequence by 2
The JDBC string I was using was: jdbc:sqlserver://[host]:[port];DatabaseName=[name];selectMethod=cursor;sendStrin‌gParametersAsUnicode=false When I changed the string to: jdbc:sqlserver://[host]:[port];DatabaseName=[name] The sequences returned were as expected: 1, 2, 3, etc

Categories : Sql Server

How do I create an Rx sequence by running tasks over original sequence's values?
This seems to work for me so far: public static IObservable<U> Select<T, U> ( this IObservable<T> source, Func<T, CancellationToken, Task<U>> selector) { return source .Select (item => Observable.Defer (() => Observable.StartAsync (ct => selector (item, ct)) .Catch (Observable.Empty<U> ()) )) .Concat (); } We map a deferred task-based exception-swallowing observable to each item, and then concat them. My thought process went like this. I noticed that one of the SelectMany overloads does almost exactly what I wanted and even has exactly the same signature. It didn't satisfy my needs though: it creates tasks as original items come up, whereas I neede

Categories : C#

find the first longest ascending or descending sub-sequence in a given unsorted sequence by C++
Well, for starters, your function will always return true. if (v.size() <1) return false; if (v.size() == 1) cout << v[0] << endl; return true; should probably be if (v.size() <1) { return false; } else if (v.size() == 1) { cout << v[0] << endl; return true; }

Categories : C++

Clojure lazy-sequence where sequence grows from both ends
If all you want is to get n members of an equivalence class, then you could define your function like this instead: (defn range-right-left [x step] (interleave (iterate #(- % step) x) (iterate #(+ % step) (+ x step)))) (take 5 (range-right-left 7 3)) ; => (7 10 4 13 1) (sort (take 5 (range-right-left 7 3))) ; => (1 4 7 10 13) The results aren't in the same order that you had before, but as the example shows you can just use sort once you have your slice of the infinite stream if you really need it in sorted order.

Categories : Clojure

Excel 2007 VBA MATCH function is not finding a match, but a match does exist in that range?
You must use MatchType of 0 to use wild card characters (* or ?) see: http://office.microsoft.com/en-001/excel-help/match-function-HP010062414.aspx Use Application.Match("More items related to*", Range("AZ1:AZ1000"), 0)

Categories : Excel

What is the proper sequence of options for gcc & the importance of that sequence?
List libraries last. After compiling, GCC passes files to the linker for linking (unless linking is not to be performed, as happens when you request compilation-only with the -c switch). It passes the files to the linker in the order you list them (or their corresponding inputs) on the command line. You listed -lpthread (which means the pthread library, named libpthread.a or something similar) followed by multi_thread_server.c (which gets compiled to an object file named multi_thread_server.o. So the linker receives the library first, then the object file. When the linker processes a library file, it extracts from it only the modules that supply a definition of a symbol that is needed to satisfy earlier references to the symbol. Since the library is the first file, there are no earlier

Categories : C

xpath 2.0: filter sequence using another sequence
Probably context is changing there. So I tried use a variable and it seems to be working. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method="xml" indent="yes" /> <xsl:variable name="refs" select="//reference" /> <xsl:variable name="files" select="doc('files.xml')/files/file[path = $refs]" /> <xsl:template match="/"> <files> <xsl:copy-of select="$files" /> </files> </xsl:template> </xsl:stylesheet> This xslt gives a result <?xml version="1.0

Categories : Misc

Sequence of group and Sequence of elements
I just tried and it seems to be working as you expect <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="test" xmlns:test="test"> <xs:group name="a_group"> <xs:sequence> <xs:element name="a" type="xs:string" /> </xs:sequence> </xs:group> <xs:group name="b_group"> <xs:sequence> <xs:element name="b" type="xs:string" /> </xs:sequence> </xs:group> <xs:element name="body"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:group ref="test:a_group

Categories : HTML

Why is Hibernate not using the next sequence value in the sequence table?
I found that my script needs to update the sequence table CREDENTIALS_SEQUENCE. In HSQL that is done as follows: alter sequence credentials_sequence restart with 13; HIBERNATE_SEQUENCES is not used.

Categories : Hibernate

Grep word in one file, and use that word to match in FASTA file, adding the FASTA sequence to the first file
One way with awk awk ' NR==FNR && />/ { x=$0 getline b a[substr(x,2)]=b next } { for (i=2;i<=NF;i++) { for (k in a) { if ($i==k) { $i=$i" "a[k] } } } }1' file2 file1 One-liner: awk 'NR==FNR{NF==2?k=$2:a[k]=$1;next}{for(i=2;i<=NF;i++){for(k in a){$i=$i==k?$i OFS a[k]:$i}}}1' FS="[> ]" file{2,1} Output with your sample data: $ awk 'NR==FNR {NF==2?k=$2:a[k]=$1;next}{for(i=2;i<=NF;i++){for(k in a){$i=$i==k?$i OFS a[k]:$i}}}1' FS="[> ]" file{2,1} Jan12345: ID1 ABCDEFG ID2 HIJKLMN IDN1 OPQRSTU Jan67899: ID11 WXYZABC ID12 DEFGHIJ IDN2 KLMNOPQ

Categories : Regex

Regex to match paths that don't match a specific pattern: Express Router
The following regex will match any path except those starting with /foo/ app.get(/^/([^f][^o][^o]|.{1,2}|.{4,})/.*$/, routes.index); I assume that this is a standard javascript regex.

Categories : Regex

Excel VBA: Can't get a match, error "Unable to get the Match property of the WorksheetFunction class"
Use the Application.Match function which allows for better ability to trap errors. When using the WorksheetFunction.Match, when a match is not found, it returns an error, which is what you're experiencing. If Not IsError(Application.Match(Cells(e, 1).Value, myrange, 0)) Then 'Do stuff when the match is found Cells(e, 3).Value = "Yes" Else: Cells(e, 3).Value = "No" End If You could also potentially use the CountIf function: If Application.WorksheetFunction.CountIf(myRange, Cells(e,1).Value) > 0 Then Cells(e,3).Value = "Yes" Else: Cells(e,3).Value = "No" End If Neither of these approaches requires you to use the m1 variable, you can assign this variable within the True part of the If/Then statement, if you need to identify where the match is found.

Categories : Excel

How to boost results in elasticsearch, so that match in field1 is always higher then match in field2?
Have you tried setting use_dis_max to be false? This should mean that a doc with "small" in category and title would be higher than a doc with "small" in just the category. As for the strange behaviour you are seeing between the 2nd and 3rd results, I am a bit lost... Can you do the query and ask for the explanation of how the scores were calculated?

Categories : Elasticsearch

Javascript string.match refuses to return an array of more than one match
You're looking for the form needle.exec(haystack) From my console: > haystack = "{List:[Names:a,b,c][Ages:1,2,3]}"; "{List:[Names:a,b,c][Ages:1,2,3]}" > needle = /^{List:[Names:([a-zA-z,]*)][Ages:([0-9,]*)]}$/g ; /^{List:[Names:([a-zA-z,]*)][Ages:([0-9,]*)]}$/g > needle.exec(haystack); ["{List:[Names:a,b,c][Ages:1,2,3]}", "a,b,c", "1,2,3"]

Categories : Javascript

Merge two data frame on one exact match and one partial URL match
You can put your data in the long format and then process by ID within a data.table . library(reshape2) dat <- do.call(rbind,lapply(list(pattern,dataset),function(x) melt(x,id.vars='SessionId'))) library(data.table) DT <- data.table(dat,key='SessionId') DT[,if(.N ==2) if(length(grep(value[1],value[2]))>0) as.list(value) ,by='SessionId'] SessionId V1 V2 1: 5b8cc8794a02ba868db21faef1 somewebsite.com/abc/detail/110302288511/ somewebsite.com/abc/detail/110302288511/110302288512/ 2: 5b8cc8794a02ba868db21faef3 somewebsite.com/abc/detail/110302288513/ somewebsite.com/abc/detail/110302288513/1103022815/ EDIT benchmarking the 2 solutio

Categories : R

How to map a sequence of discriminated unions (where all items are of the same case) onto a sequence of items of the type of the case?
You are assuming your sequence contains not a single case1, so if this is not true you need to throw an exception. let matchCase item = match item with | Case1 x -> failwith "Unexpected Case1" | Case2 x -> x let case2s = Seq.map matchCase union1s An alternative approach, if you are not sure the sequence contains always the same case is to use an Option let matchCase item = match item with | Case1 x -> None | Case2 x -> Some x Then it depends on how you will handle these cases, you can just filter out the None values using Seq.choose instead of Seq.map as shown on the other answer. Which approach to follow depends if you consider having an argument with Case1s an exceptional case or part of the logic of your program. There was a question regardin

Categories : F#

Should I expect to have exactly same match everytime I run the match with greedy algorithm?
"Greedy" doesn't necessarily mean "deterministic," in particular if you have two choices with equal weight/value then it may be possible to first select one choice during one algorithm execution and to first select the other choice on another algorithm execution.

Categories : Algorithm

PHP MySQL query: match two tables with percentage match
Try below: SELECT e_id, e.skill, c.skill, (e.points/c.points)*100 from employee_skills as e, company_skills as c WHERE e.skill = c.skill GROUP BY e.e_id,e.skill See below: SELECT c.skill, total_emp_points, c.points as total, (total_emp_points/c.points)*100 as percnt FROM company_skills AS c, (SELECT e.skill, SUM(e.points) as total_emp_points FROM employee_skills as e GROUP BY e.skill) as emp WHERE c.skill = emp.skill; see SqlFiddle

Categories : PHP

compare 2 tables if match update if not match insert
The easiest way is a MERGE statement: MERGE INTO Table_B USING Table_A ON TableA.ID1 = Table_B.ID1 AND TableA.ID2 = Table_B.ID2 AND TableA.ID3 = Table_B.ID3 WHEN MATCHED THEN UPDATE SET A = Table_A.A, B = Table_A.B -- Etcetera... WHEN NOT MATCHED THEN INSERT (A, B) VALUES (Table_A.a, Table_A.B) -- Etcetera... WHEN NOT MATCHED BY SOURCE THEN DELETE -- If Necessary... ; By the way, don't forget the ";" at the end. SQL Server doesn't usually need them, but a MERGE does.

Categories : Sql Server



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