[Solved] Running total for list of dict

I assumed date is increasing order. # store values tot = {} # the last date date0 = Dict1[-1][‘date’] # easier to work from back, i found for line in Dict1[-1::-1]: date, name, qty = [line[x] for x in ‘date’, ‘name’, ‘qty’] # add the value to all subsequent days for d in range(date, date0+1): … Read more

[Solved] Find pattern in Html using regex [closed]

try this: preg_match_all(“/(<span>\d{4}<\/span>)/”, $myinput, $myoutput); http://3v4l.org/72ClO please note this does not parse html. it looks for something that starts with <span> then has 4 digits, then </span>. A single space in there, and will fail. use this one to get the 4 digits only preg_match_all(“/<span>(\d{4})<\/span>/”, $myinput, $myoutput); http://3v4l.org/FF4Y9 solved Find pattern in Html using regex … Read more

[Solved] Java incrementing every character in a string by a large amount?

First I’m going to remove all of the I/O (except for outputting the result), get rid of the decryption piece for brevity, and write encrypt(String) and encrypt(char) as pure functions. public class EncryptionMain { public static void main(String args[]){ System.out.println(encrypt(“Hello”)); } static String encrypt(String plaintext) { StringBuilder ciphertext = new StringBuilder(plaintext); for (int i = … Read more

[Solved] Why does assignment to parameter not change object?

The observed behavior has nothing to do with Value types vs Reference types – it has to do with the Evaluation of Strategy (or “calling conventions”) when invoking a method. Without ref/out, C# is always Call by Value1, which means re-assignments to parameters do not affect the caller bindings. As such, the re-assignment to the … Read more

[Solved] Failing Regex string thats correct

I don’t see the problem. The regex works in the Regex Hero online tester (including the capture group capturing “Beta”)… …and works in the following VB.NET snippet it generated (to which I added a Console.WriteLine call for clarity): Dim strRegex as String = “Version:</b>\s*<span>(.*)\<” Dim myRegex As New Regex(strRegex, RegexOptions.None) Dim strTargetString As String = … Read more

[Solved] C binary read and write file

Okay, I don’t really understand what’s going on, but it seems that you cannot trust fseek with SEEK_CUR when using with read/write files in that case (I’m running Windows, and the standard functions are notoriously different from Linux that may be the issue) EDIT: Andrew’s answer confirms my suspicions. My solution complies to what the … Read more

[Solved] $_POST disappears in IE and FF?

If you write any value in URL it is not $_POST value but $_GET value. If you launch url: http://localhost/index.php?id=2 you should in your php code use: $_GET[‘id’] to determine what’s the value if id in URL 3 solved $_POST disappears in IE and FF?

[Solved] Cannot use array with GCC

Because <array> got indirectly included from somewhere and you made the mistake of using namespace std, “array” in ErrorMessage refers to that name in the std namespace. That is a class template, not a type – hence the error message. Outside of value, its array is called value::array. (The typedef value::array array in value is … Read more

[Solved] Extract data from a string [duplicate]

Using builtin .NET classes, you can use System.Web.Extensions public class Person { public string Name { get; set; } public int Age { get; set; } } Then in your code, you can deserialise the JSON i.e. public void GetPersonFromJson(string json) { //… json = ” [{\”Name\”:\”Jon\”,\”Age\”:\”30\”},{\”Name\”:\”Smith\”,\”Age\”:\”25\”}]”; JavaScriptSerializer oJS = new JavaScriptSerializer(); Person[] person = … Read more

[Solved] How can I count the keys inside a for each loop?

function findKey($array, $keySearch) { global $count; foreach ($array as $key => $item) { if (stripos($key, $keySearch) !== false){ $count++; echo “<li>”.$key.”</li>”; } if (is_array($item)){ findKey($item, $keySearch); } } } $count = 0; findKey($array, $keySearch); echo “Total number of keys: “.$count; 7 solved How can I count the keys inside a for each loop?