w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Problem to plot 3D surface with R‏
Try this to see why I don't think this data is well suited for wireframe: cloud(Z~X+Y, data=FI02, xlab="X", ylab="Y", main="Surface elevation", type="l", screen=list(z=-60, x=-60))

Categories : R

kruskal.test shows "All group levels must be finite" error. What is the problem?
It should work if you run data$Grp <- as.factor(data$Grp) Then (as before): kruskal.test(data$Val, data$Grp) This is because Grp is a character not a factor and is.finite applied to an object of character class is always false (see ?is.finite).

Categories : R

Searching a list of strings to return only those strings that match another input list of strings in Linq
var result = S.Where(x=> X.Any(y=>x.EndsWith(y))); If you want to ignore case: var result = S.Where(x => X.Any(y => x.EndsWith(y, StringComparison.CurrentCultureIgnoreCase)));

Categories : C#

Combine strings. Count how many indices (from list) are in original strings. Python
You can use collections.Counter and bisect.bisect_left here: >>> from collections import Counter >>> import bisect >>> junctions = [2,9,15,20] >>> seq_1 = 'sauron' >>> seq_2 = 'corrupted' >>> seq_3 = 'numenor' >>> lis = [seq_1, seq_2, seq_3] Create a list containing the indexes at which at each seq_ ends: >>> start = -1 >>> break_points = [] for item in lis: start += len(item) break_points.append(start) ... >>> break_points [5, 14, 21] Now we can simply loop over junctions and find each junction's position in the break_points list using bisect.bisect_left function. >>> Counter(bisect.bisect_left(break_points, jun)+1 for jun in junctions) Counter({3: 2, 1: 1, 2: 1}) B

Categories : Python

How can I pass the Strings from an ArrayList to a method that takes in multiple Strings?
You can do something like this: ArrayList<String> list = new ArrayList<String>(); // Filling the list with strings... String[] stringArray = new String[list.size()]; list.toArray(stringArray); addStrings(stringArray); public addStrings(String... args) { // Do something with those Strings } Pass your strings in a primitive array. From the varargs documentation: The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. All you'd need to do is derive a String[] from your List and then pass it to the addStrings(String... args) method. Credit to this question for the documentation link.

Categories : Android

joining strings with a separator and taking into account empty strings
You can try using the inline terniary within the Join method: string.Join("-", string.IsNullOrEmpty(e.Company) ? "fired" : e.Company, e.Name) Edit (I misread 'fred' for misspelled fired). As mentioned in another answer, an extension method would clean up the code. You will be moving ugly code to a different place. As an alternative to an extension method, I would recommend something like the following that allows for more parameters at a later time: public static string ExcludeEmptiesJoin(params string[] args) { string outValue = string.Empty; foreach (var arg in args.Where(s => !string.IsNullOrEmpty(s))) { if (string.IsNullOrEmpty(outValue)) { outValue = arg; } else { outValue = string.Join("-", outValue, arg); } }

Categories : C#

Why does a less than or more than comparison in PHP of two strings in the date format of "YYYY-MM-DD" work even though they are strings?
When you compare a string this way, it will go from left to right, and compare each character in the given string to see if they are different, until it finds a difference, then it will decide which string is bigger by comparing the ASCII value of this last character. Coincidentally, since you are using only numbers, the highest numbers are also higher on the ASCII table. This solution will work as long as you use only numbers in your comparisons, and that each string has the same number of characters Also note that this works only since you are using the YYYY-MM-DD format, if you used another format it would not work.

Categories : PHP

Converting a list of strings to flat strings in Emacs?
To pass a list of arguments to a function you can use apply, for example (apply 'insert '("hello " "world"))

Categories : Emacs

Java Strings : how the memory works with immutable Strings
Yes, that sounds about right. Probably even more because your 1MB byte array needs to be turned into UTF-16, so depending on the encoding, it may be even bigger (2MB if the input was ASCII). Note that the garbage collector can reclaim memory as soon as the variables that use it go out of scope. You could set them to null as early as possible to help it make this as timely as possible (for example responseData = null; after you constructed your String). if yes, then what is the optimal way to fix this "Fix" implies a problem. If you have enough memory there is no problem. the problem is that I am getting OutOfMemoryException as the byte[] data coming from server is quite big, If you don't, you have to think about a better alternative to keeping a 1MB string in memory. Maybe yo

Categories : Java

Im trying scramble randomaly strings but some of the strings dosen't get scrambled at all what could it be?
Instead of randomly swapping two locations, swap every location to a random location... it will look more random because each element will have moved. With your current design there is a good chance some items won't ever move. for (int i = 0; i < lengthSb; ++i) { int index1 = i; int index2 = (RandomGen.Next() % lengthSb); Char temp = jumbleSb[index1]; jumbleSb[index1] = jumbleSb[index2]; jumbleSb[index2] = temp; }

Categories : C#

Android: strings resource, multiple strings with the same name
maybe you can use some thing like <string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string> see http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling so for your example <string name="CourseInfo2">Course Information%1$s</string> and then Resources res = getResources(); String text = String.format(res.getString(R.string.CourseInfo2), ":"); String text2 = String.format(res.getString(R.string.CourseInfo2), ":-");

Categories : Android

Automatically removing unreferenced strings from strings.xml
Android Lint can do it for you. Try: Right clic on your project > Android Tools > Run Lint: Check for Common Errors. Depending on your Lint settings, the unused strings will be shown.

Categories : Android

PHP – Substitute multiple similar strings with other different strings
You can use preg_replace_callback that allows you to use a function as replacement. $txt = preg_replace_callback('~[var-(d+)]~', function ($match) { return $var[$match[1]]; }, $txt); If you want to extract the values from an XML document, using XPath is a good way. Example: $str = "Hey I am some text,[var-1] a lot of these [var-3] parts will have" . " to [var-9] go away and be exchanged [var-2] by others"; $xml = <<<'LOD' <?xml version="1.0"?> <Variations> <Variation id="1">really</Variation> <Variation id="2">quickly</Variation> <Variation id="3">strange</Variation> <Variation id="9">definitely</Variation> </Variations> LOD; $doc = new DOMDocument(); @$doc->loadXML($xml); $xpath

Categories : PHP

Elegantly appending a set of strings (.txt file) to another set of strings (.txt also)?
Here is a solution in C#. You run it like: joinfiles a.txt b.txt c.txt where a.txt is the first file, b.txt the second one, and c.txt the output file that will be created. It generates the output at 100 MB/s on my machine so that is probably fast enough. using System; using System.IO; using System.Text; namespace JoinFiles { class Program { static void Main(string[] args) { if (args.Length != 3) return; string[] file1, file2; try { using (var sr1 = new StreamReader(args[0])) using (var sr2 = new StreamReader(args[1])) { file1 = sr1.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

Categories : SQL

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

Qt just loads the translations of UI strings but not strings in the code
I want to explain the solution for somebody in the situation like me. Consider I have a class named MyForm. I defined a namspace for my project called MyNmeSpace. /* MyForm.cpp */ using namespace MyNmeSpace; MyForm::MyForm(QWidget* parent):QMainWindow(parent) {} 1) If the user wraps the strings in the tr() function, they won't be translated. For enabling translation, he must use the QApplication::translate("ClassName", "str", 0, QApplication::UnicodeUTF8) like: /* MyForm.cpp approach 1 */ using namespace MyNmeSpace; MyForm::MyForm(QWidget* parent):QMainWindow(parent) { bool condition; /* sth you like */ if ( condition ) // ui.setWindowTitle(tr("MainWindow")); <= won't work ui.setWindowTitle(QApplication::translate("MyForm", "MainWindow", 0, Q

Categories : Qt

Objective C : constant strings and c strings
It seems to me that the literal syntax considers that an error NSArray *colors = @[@"Red", @"Green", "Blue", @"Yellow"]; Like seen below

Categories : Objective C

sscanf for separate strings (more than 2 strings)
You are writing past the end of your string buffers. When given a conversion spec like "%6[^ ]". the scanf() family of functions will read up to 6 characters from the stream (or string in this case) to put into the specified buffer. Then it will null terminate the buffer - so your buffer needs to be at least one character larger than the length specification you provide.

Categories : C

how to modify strings in a list of strings
Use a list comprehension: lines = ['~$ ' + line for line in command.split(' ')] If you have to use a for loop, you'd use enumerate() to include an index so you can replace the individual items in the list: for i, line in enumerate(lines): lines[i] = '~$ ' + line

Categories : Python

Sorting an ArrayList of mixed integers and strings while preserving relative ordering of strings and integers
One option here is to do the following: Create a new list of all the integers in the original list. Create a new list of all the strings in the original list. Sort each list. Iterate over the original list, doing the following: If the element there is an integer, write back the next unwritten integer from the sorted integer list. If the element there is a string, write back the next unwritten string from the sorted string list. This is quite efficient - you just need to do two sorts. Here's some code for it: public void relativeOrderSort(List<Object> list) { /* Create a list of just the integers and just the strings * from the original list. */ List<Integer> intList = new ArrayList<Integer>(); List<String> strList = new ArrayList<Str

Categories : Java

Remove empty strings from array while keeping record of indexes with non empty strings
Loop through the array and check if each element is empty. If it's not, add its position to one array and its value to another array: var elems, positions for (var i = 0; i < arr.length; i++){ if (arr[i] != ""){ elems.push(arr[i]) positions.push(i) } } EDIT: This will leave you with 3 arrays (original, elements, positions). If you would rather just modify the original one use arr.filter()

Categories : Javascript

Java - Append quotes to strings in an array and join strings in an array
You can create the code for this functionality yourself as well: String output = ""; for (int i = 0; i < listOfStrings.length; i++) { listOfStrings[i] = """ + listOfStrings[i] + """; output += listOfStrings[i] + ", "; }

Categories : Java

find the length of smallest unique sub strings given 1000 of strings of length 100
Create array of char*, each element is pointer to each symbol in the your strings. For your problem, array size is 100x1000 = 100000 char* pointers. O(N) Sort this array as "strings in alphabet order". O(N*Log(N)) Scan strings, and for each [i]-th string search max_eq_prefix between this string and strings [i+1] and [i-1]. For first and last strings run single comparisons, with [i+1] for first, and [i-1] for last. O(N) String with minimal max_eq_prefix is your substring, length is length(max_eq_prefix) + 1. Example to figure out max_eq_prefix: i-1:aabala i: aabumba i+1:acron For string [i], max_eq_prefix is aab. So, unique substring is "aabu". As you see, this is kind of minimax algorithm.

Categories : C++

MYSQL Replace array of strings with a randomly chosen array of strings
If you are looking for a quick and dirty solution, you could use something like this: UPDATE emails SET emails.address = CONCAT(SUBSTRING_INDEX(emails.address, '@', 1), '@', ELT(1+rand()*3, 'd.com', 'e.com', 'f.com', 'g.com')) WHERE SUBSTRING_INDEX(address, '@', -1) IN ('a.com', 'b.com', 'c.com') Please see fiddle here. Using SUBSTRING_INDEX(address, '@', -1) you can get the domain part of the address, and you can check if it is a.com, b.com, c.com, etc. Then you can update your email address, concatenating the first part of the address SUBSTRING_INDEX(address, '@', -1), the separator @, and a randomly chosen domain using ETL function: ELT(1+rand()*3, 'd.com', 'e.com', 'f.com', 'g.com') where 1+3 is the number of elements.

Categories : Mysql

Find if a String in a list of Strings is in another list of Strings in Esper
You'd want to look at enumeration methods, see http://esper.codehaus.org/esper-4.9.0/doc/reference/en-US/html_single/index.html#enumerationreference It seems that "intersect" and "countOf" in combination would suit.

Categories : Java

Find strings in strings
You can try with this pattern: /"((?:[^"\]+|\"|\)*)"|'((?:[^'\]+|\'|\)*)'/g Content inside double quote is in group 1, content inside single quote is in group 2. Notice: this solution is not totally waterproof for escaped quotes because if ", that can detect the pattern above, is preceded by another , then the \ is seen as a literal and the quote is no more escaped! To avoid this trap, you can check cases when you have an odd number of backslashes replacing \" by (?:\{2})*\", then the first pattern will look like this: /"((?:[^"\]+|(?:\{2})*\"|\)*)"|'((?:[^'\]+|(?:\{2})*\'|\)*)'/g

Categories : Javascript

How to convert array with elements utf8 strings to NSArray with elements utf8 strings in objective c
I assume utfStringArray is terminated with a NULL, else you'll need to provide the element count separately. I am also assuming ARC. Note I am using NSData as you have stipulated that NSString's cannot be used (for some reason): unsigned char **utfStringArray = ...; NSMutableArray *array = [[NSMutableArray alloc] init]; for (unsigned i = 0; utfStringArray[i] != NULL; i++) { NSData *data = [NSData dataWithBytes:utfStringArray[i] length:strlen(utfStringArray[i])]; [array addObject:data]; }

Categories : Objective C

Find matches of a vector of strings in another vector of strings
You can try pasting your "keywords" together and separate them with the pipe character (|) which will work like an "or", like this: > articles[grepl(paste(keywords, collapse="|"), articles$text),] id text 1 1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 2 2 tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 4 4 consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

Categories : R

JNI strings and C strings
No, according to the first reference I found, it means it should be encoded like this: FindChar("java/lang/Stringxc0x80"); ^ | | This is not the shortest way to encode the codepoint U+0000, which is why it's "modified" UTF-8. Note that this assumes that you're really looking for class names whose names end in U+0000, which is rather unlikely. The C string should be terminated just like normal, with a single 0-byte as you get from just: FindChar("java/lang/String"); The special 2-byte encoding of U+0000 provided by Modified UTF-8 only matters if you want to put U+0000 in a string, and still be able to differentiat

Categories : Java

strings one after the other in c : "...""...", as if they were concatenate
No, this is not a feature of fprintf(), that would be impossible (how would you implement such a function yourself?) since fprintf() is just a standard function with no extra magic done by the compiler. It's a feature of C's syntax: adjacent string literals are treated as a single literal by just concatenating them together. It's very useful together with the preprocessor's stringification support, for instance.

Categories : C

Get difference between strings
<?PHP $first = "|x|67|x|194|x|113|x|6|x|"; $second = "|x|194|x|113|x|6|x|109|x|"; $first_array = explode("|x|", $first); $second_array = explode("|x|", $second); $not_in_first_array = array(); $not_in_second_array = array(); foreach( $first_array as $a ) { if( ! in_array( $a , $second_array ) ) { $not_in_second_array[] = $a; } } foreach( $second_array as $a ) { if( ! in_array( $a , $first_array ) ) { $not_in_first_array[] = $a; } } print_r( $not_in_second_array ); print_r( $not_in_first_array ); ?>

Categories : PHP

Not displaying strings
If you're OK with your JFrame being re-sized by the program (not by users), you can try pack() that is supposed to work even with setResizable set as false. If however you don't want to allow any type of re-sizing, then you need to explain your question further.

Categories : Java

Strings in BigEndianStructure
This type: class PacketString(BigEndianStructure): _fields_ = [("length", c_ushort), ("value", c_char_p)] … doesn't do what you think it does, even ignoring the endianness issue. It's a struct that contains a ushort length, and then a pointer to the actual string data somewhere else in memory. In other words, it's just like this C structure: struct PacketString { unsigned short length; char *value; }; What you're looking for is a length-prefixed string, where the string is directly inline inside the struct. For that, the C structure is: struct PacketString { unsigned short length; char value[1]; }; This is called the "struct hack". This is not actually legal C, but it happens to work with every known C89 compiler, and most C99 and C++ compil

Categories : Python

Get the substring that is in between two strings php
explode might need a workaround because ( and ) are different. A simple regex will get the job done. $string1 = "(substring1) Hello"; preg_match('#((.*?))#', $string1, $match); // preg_match_all if there can be multiple such substrings print $match[1];

Categories : PHP

When sorting strings should é come before e
Best practice is to sort without diacritics first, ie. cafe comes before café. localeCompare works by stripping the diacritics, so the sort order doesn't reflect the real words, since café is turned into cafe You can read more about localeCompare here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

Categories : Javascript

Why strings are not equal
You can use an intermediate variable, like this String buttonText = b.getText().toString(); if (buttonText.equals(PLAY)) { ..... Or just if (b.getText().toString().equals(PLAY)) {

Categories : Android

How to leave max value in Map of Strings
how about a simple compare: if the key exist then get the value using the key. Compare the value with the new value using Math.MAX and re-insert using the key. The value will be overwritten by the max value. Map<String, Integer> list = new HashMap<String, Integer>(); String key="FOO"; String s[]={"123","012","789"}; for(String numStr: s) { int value = Integer.parseInt(numStr); if(!list.containsKey(key)) list.put(key, value); else list.put(key, Math.max(value, list.get(key))); } System.out.println( list.get(key) ); result is 789

Categories : Java

Matching 2 strings
You are looking for a string to split, not a regular expression listOfWordsArray = listOfWords.split("/ ? /"); You do not want the quotes listOfWordsArray = listOfWords.split(/ ? /);

Categories : Javascript

Best way to filter these strings PHP
With explode $arr = explode(';',$str); $arr = $arr[count($arr) - 2]; // get the last link $arr = trim($arr,"arrayImg[0]="); //here you will get only the last link Live Demo Most of people stuck in situation whether they have to use regex or any other predefined functions. You have to use predefined functions if your task can be accomplished with them otherwise use regex if none of them available to accomplish your task.

Categories : PHP

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



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