string

For each result in MySQL query, push to array (complicated)

Okay, here's what I'm trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then within that ID in the array, I need to add more data from the rows. A multi-dimensional array. Here's my code thus far. $query = "SELECT * FROM posts ORDER BY id DES...

Whats the best way to send multiple variables in a query string within a URL

I have a client who is wanting to create a link which contains product codes so that his customers hit a page with just those products displayed in an attempt to increase conversion rates from affilliate sites. My question is whats the best way to send these multiple products in a single URL For example: http://www.mydomain.co.uk/besp...

Regex: Strip non alpha numeric or punctuation.

How can I use PHP to strip out all characters that are NOT alpha, numeric, space, or puncutation? I've tried the following, but it strip punctuation. preg_replace("/[^a-zA-Z0-9\s]/", "", $str); ...

Scala capture group using regex

Let's say I have this code: val string = "one493two483three" val pattern = """two(\d+)three""".r pattern.findAllIn(string).foreach(println) I expected findAllIn to only return 483, but instead, it returned two483three. I know I could use unapply to extract only that part, but I'd have to have a pattern for the entire string, something...

Translating a String - character by character

How should I go about implementing a method that gets a String composed of Latin characters to translate it into a String composed of a different set of characters, let's say Cyrillic. Here's how it's done in PHP for example: function latin_to_cyrillic($string) { $array = array( "а" => "a", "б" => "b", "в" => "v", "г" => "g", ...

Question about references in java

I want to know what the difference between : String s = "text"; and : String s = new String("text"); ...

What the best way to convert from String to HashMap?

I would like to serialize a Java HashMap to string representation. The HashMap will contains only primitive values like string and integer. After that this string will be stored to db. How to restore back the HashMap? Is it make sense to use BeanUtils and interface Converter or use JSON? For example: List list = new ArrayList(); ...

How can I write character & in android strings.xml

I wrote the following in the strings.xml file: <string name="game_settings_dragNDropMove_checkBox">Move by Drag&Drop</string> I got the following error: The reference to entity "Drop" must end with the ';' delimiter. How can I write character & in the strings.xml? ...

Why might a System.String object not cache its hash code?

A glance at the source code for string.GetHashCode using Reflector reveals the following (for mscorlib.dll version 4.0): public override unsafe int GetHashCode() { fixed (char* str = ((char*) this)) { char* chPtr = str; int num = 0x15051505; int num2 = num; int* numPtr = (int*) chPtr; for ...

C - Convert time_t to string with format YYYY-MM-DD HH:MM:SS

Hello, is there any way to convert a time_t to a string with the format YYYY-MM-DD HH:MM:SS automatically, keeping the code portable? ...

Access COM server's idl helpstring attribute from .net client

I haven't been able to find a way to access the helpstring attribute of a COM server's interface method's or properties from a .net client? Is it possible? I've created a primary interop assembly for my COM server using the command: tlbimp myserver.tlb /primary /keyfile:myserver.snk /out:company.myserver.dll /namespace:myserver The int...

Add string to another string

Hi there, I currently encountered a problem: I want to handle adding strings to other strings very efficiently, so I looked up many methods and techniques, and I figured the "fastest" method. But I quite can not understand how it actually works: def method6(): return ''.join([`num` for num in xrange(loop_count)]) From source (Met...

Iterate over the lines of a string

I have a multi-line string defined like this: foo = """ this is a multi-line string. """ This string us used as test-input for a parser I am writing. The parser-function receives a file-object as input and iterates over it. It does also call the next() method directly to skip lines, so I really need an iterator as input, not an itera...

String.Format not converting integers correctly in arabic

I have a problem with String.Format. The following code formats the string correctly apart from the first integer. Current culture is set to Iraqi arabic (ar-IQ): int currentItem= 1; string of= "من"; int count = 2; string formatted = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", currentItem, of, count); The text is formatted ...

How does string comparison work in OCAML?

From what I can tell, = and != is supposed to work on strings in OCAML. I'm seeing strange results though which I would like to understand better. When I compare two strings with = I get the results I expect: # "steve" = "steve";; - : bool = true # "steve" = "rowe";; - : bool = false but when I try != I do not: # "steve" != "rowe";...

Create a modifiable string literal in C++

Is it possible to create a modifiable string literal in C++? For example: char* foo[] = { "foo", "foo" }; char* afoo = foo[0]; afoo[2] = 'g'; // access violation This produces an access violation because the "foo"s are allocated in read only memory (.rdata section I believe). Is there any way to force the "foo"s into writable ...

is there any faster way to parse than by walk each byte?

is there any faster way to parse a text than by walk each byte of the text? I wonder if there is any special CPU (x86/x64) instruction for string operation that is used by string library, that somehow used to optimize the parsing routine. for example instruction like finding a token in a string that could be run by hardware instead of...

How to format output using MATLAB's num2str

I'm trying to ouput an array of numbers as a string in MATLAB. I know this is easily done using num2str, but I wanted commas followed by a space to separate the numbers, not tabs. The array elements will at most have resolution to the tenths place, but most of them will be integers. Is there a way to format output so that unnecessary tra...

Does String.fromCharCode(decimal value) in javascript supports extended characters also.

Hi, I am using function String.fromCharCode(decimal value), and passing a decimal value to it. its working fine in terms of English characters, but when i m trying the same to decode for the Japanese characters, it gives me some arbit characters. can anyone tell me does String.fromCharCode(decimal value) supports extended charact...

Passing a string parameter in a JavaScript function on MVC

Hi there, I tried to pass a string value into a JavaScript function like below: <%= "'" + prop.property_description + "'") %>) But it does not seems to be the best option, is there a better way to do the above without concatenate the string values with "'"? Thanks ...