string

How can I map a String to a function in Java?

Currently, I have a bunch of Java classes that implement a Processor interface, meaning they all have a processRequest(String key) method. The idea is that each class has a few (say, <10) member Strings, and each of those maps to a method in that class via the processRequest method, like so: class FooProcessor implements Processor { ...

Adding string to end of URL

To practise some more bits of python I've been having a go at the challenges on pythonchallenge.com In brief, this challenge as a first step requires one to load an html page from a url with a number at the end. The page contains a single line of text which has in it a number. That number is used to replace the existing one in the url, ...

Python - converting wide-char strings from a binary file to Python unicode strings...

It's been a long day and I'm a bit stumped. I'm reading a binary file that contains lots of wide-char strings and I want to dump these out as Python unicode strings. (To unpack the non-string data I'm using the struct module, but I don't how to do the same with the strings.) For example, reading the word "Series": myfile = open("test...

String Length Evaluating Incorrectly

My coworker and I are debugging an issue in a WCF service he's working on where a string's length isn't being evaluated correctly. He is running this method to unit test a method in his WCF service: // Unit test method public void RemoveAppGroupTest() { string addGroup = "TestGroup"; string status = string.Empty; string mess...

PHP: Extract direct sub directory from path string

I need to extract the name of the direct sub directory from a full path string. For example, say we have: $str = "dir1/dir2/dir3/dir4/filename.ext"; $dir = "dir1/dir2"; Then the name of the sub-directory in the $str path relative to $dir would be "dir3". Note that $dir never has '/' at the ends. So the function should be: $subdir ...

What is the absolute simplest way for an ASP.NET client to communicate a single string value (defined in the code) to the server?

I just need the client-side JavaScript to be able to send a string value to the ASP.NET server app. What's the common opinion on this process? ...

Create a SortedMap in Java with a custom Comparator

I want to create a TreeMap in Java with a custom sort order. The sorted keys which are string need to be sorted according to the second character. The values are also string. Sample map: Za,FOO Ab,Bar ...

How would you create a string of all UTF-8 characters? [PHP]

There are many ways to represent the +1 million UTF-8 characters. Take the latin capital "A" with macron (Ā). This is unicode code point U+0100, hex number 0xc4 0x80, decimal number 196 128, and binary 11000100 10000000. I would like to create a collection of the first 65,535 UTF-8 characters for use in testing applications. These are a...

string comparison InvariantCultureIgnoreCase vs OrdinalIgnoreCase?

Which would be better code: int pos = file.dmFileDescr.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase); or int pos = file.dmFileDescr.LastIndexOf(".", StringComparison.OrdinalIgnoreCase); ...

How to remove trailing symbol for a constant in Rails initializer?

How does one remove trailing character correctly in the following sentence if it's in config/environment.rb file. KEY = ENV['KEY'].delete "\r" It produces the following error: undefined method `delete' for nil:NilClass (NoMethodError) It works well in IRB, but not in environment.rb Solved Aptana Studio 3 stopped to load .bashrc a...

Correct way to initialize a NULL-terminated array of strings in C

Is this code correct? char *argv[] = { "foo", "bar", NULL }; ...

PHP get values from SimpleXMLElement array

I have this: [1]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(14) { ["name"]=> string(5) "MySQL" ["acknowledged"]=> string(1) "1" ["comments"]=> string(1) "1" ["current_check_attempt"]=> string(1) "1" ["downtime"]=> string(1) "0" ["last_check"]=> string(19) "2010-05-01 ...

Algorithm detect repeating/similiar strings in a corpus of data -- say email subjects, in Python

I'm downloading a long list of my email subject lines , with the intent of finding email lists that I was a member of years ago, and would want to purge them from my Gmail account (which is getting pretty slow.) I'm specifically thinking of newsletters that often come from the same address, and repeat the product/service/group's name in...

Jquery convert integer to string and back

These are the logical steps which I need to do with jquery: x is a 2 digit number(integer) derived from an input.value(); If var x is **not** 33 or 44 Convert this 2 digit number to string; split the string in 2 parts as number; Add these 2 values until they reduce to single digit; Return var x value as this value; Els...

Searching within an array of strings...

Ok, I'm feeling retarded here, I have a string like so: $string = 'function module_testing() {'; or it could be like this: $string = 'function module_testing()'; or it could be like this: $string = 'function module_testing($params) {'; or this: $string = 'function module_testing($params, $another = array())'; and many more w...

Convert a raw string to an array of big-endian words with Ruby

Hello, I would like to convert a raw string to an array of big-endian words. As example, here is a JavaScript function that do it well (by Paul Johnston): /* * Convert a raw string to an array of big-endian words * Characters >255 have their high-byte silently ignored. */ function rstr2binb(input) { var output = Array(input.lengt...

What is the fastest way to trim blank lines from beginning and end of array?

This script: <?php $lines[] = ''; $lines[] = 'first line '; $lines[] = 'second line '; $lines[] = ''; $lines[] = 'fourth line'; $lines[] = ''; $lines[] = ''; $lineCount = 1; foreach($lines as $line) { echo $lineCount . ': [' . trim($line) . ']<br/>'; $lineCount++; } ?> produces this output: 1: [] 2: [first line] 3: [sec...

Displaying "Google like" search results

Working in ASP.NET (VB), I am trying to develop a simple search results page for my website. The process is as follows: (1) The site's user enters a search phrase; (2) The search results page searches the site's database, returns the page title as a link, and a short snippet from each search "hit", with the search phrase highlighted...

String contains string in objective-c (iphone)

How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @"hello bla bla"; NSLog(@"%d",[string containsSubstring:@"hello"]); But the closest I could find was: if ([string rangeOfString:@"hello"] == 0) { NSLog(@"sub string doesnt exist"); } else { NSLog(@"exist...

Best way for saving infinit playlists (arrays) into db? (php mySql)

So client gives me a string like "1,23,23,abc,ggg,544,tf4," from user 12 . There can be infinit number of elements with no spaces just value,value,... structure. I have users table (with users uId(key), names etc). I have streams table with ( sId(key), externalID, etc values). User sends me externalId's. And I need to hawe externalId's ...