string

Looking for a tool to quickly test C# format strings

I am constantly forgetting what the special little codes are for formatting .NET strings. Either through ToString() or using String.Format(). Alignment, padding, month vs. minute (month is uppercase M?), abbreviation vs. full word, etc. I can never remember. I have the same problem with regexes, but luckily there's Expresso to help me o...

How to determine width of a string when printed?

I'm creating a custom control, part of which is using the Graphics class to draw text to the form. Currently I'm using the following code to display it: private float _lineHeight { get { return this.Font.Size + 5; } } private void Control_Paint(object sender, PaintEventArgs e) { Graphics g = this.CreateGraphics(); Brush b = new ...

What's the simplest way to return the first line of a multi-line string in Perl?

When I say simple, I mean, within an expression, so that I can stick it in as a value in a hash without preparing it first. I'll post my solution but I'm looking for a better one that reminds me less of VB. :) ...

String search

What is the best way to search strings for something like forum? i seen horrible string search and typically get worse the more strings you use rather then better. I also may implement a title search so if the way to search title that is better then a body of string i'd love to hear that too ...

C# Switch with String.IsNullOrEmpty

Is it possible to have a switch in C# which checks if the value is null or empty not "" but String.Empty? I know i can do this: switch (text) { case null: case "": break; } Is there something better, because I don't want to ...

"stringWithString" vs "alloc ... initWithString ... autorelease" in Cocoa Objective-C.

I've seen it claimed that the following are "pretty much equivalent": foo([NSString stringWithString:@"blah"]) # version 1 foo([[[NSString alloc] initWithString:@"blah"] autorelease]) # version 2 Are the above in fact literally equivalent or are there any subtle differences? What are reasons to prefer one or th...

PHP: Convert a String to Variable

I've got a multidimensional associative array which includes an elements like $data["status"] $data["response"]["url"] $data["entry"]["0"]["text"] I've got a strings like: $string = 'data["status"]'; $string = 'data["response"]["url"]'; $string = 'data["entry"]["0"]["text"]'; How can I convert the strings into a variable to access ...

(Encoded) String handling in C++ - questions / best practices?

What are the best practices for handling strings in C++? I'm wondering especially how to handle the following cases: File input/output of text and XML files, which may be written in different encodings. What is the recommended way of handling this, and how to retrieve the values? I guess, a XML node may contain UTF-16 text, and then I ...

How to reverse a Unicode string

It was hinted in a comment to an answer to this question that PHP can not reverse Unicode strings. As for Unicode, it works in PHP because most apps process it as binary. Yes, PHP is 8-bit clean. Try the equivalent of this in PHP: perl -Mutf8 -e 'print scalar reverse("ほげほげ")' You will get garbage, not "げほげほ". – jrockway ...

Changing XSD ConnectionString at Runtime for a Multitenant app

Hello, I'm changing our application from "one set of code & one database" to "one set of code to multiple databases (one database per customer)". The original code is VS2005 ASP.NET(VB) & lots of XSD's in a separate DLL. The web.config's ConnectionString would override the one stored in the DLL at runtime. Now I need to change the Con...

Looking for String operations edge cases. What do I need to test?

I am getting to the last stage of my rope (a more scalable version of String) implementation. Obviously, I want all operations to give the same result as the operations on Strings whenever possible. Doing this for ordinal operations is pretty simple, but I am worried about implementing culture-sensitive operations correctly. Especially...

How to portably convert a string into an uncommon integer type?

Some background: If I wanted to use for, for instance, scanf() to convert a string into a standard integer type, like uint16_t, I’d use SCNu16 from <inttypes.h>, like this: #include <stdio.h> #include <inttypes.h> uint16_t x; char *xs = "17"; sscanf(xs, "%" SCNu16, &x); But a more uncommon integer type like pid_t does not have any suc...

Is this a bug in string.TrimEnd?

"\u4000\f".TrimEnd(new char[0]) is equal to "\u4000". I am passing an empty array, so according to the MSDN documentation nothing should be removed and "\u4000\f" should be returned. Is there a reason for this behaviour? EDIT: Clarified expected behaviour EDIT: Apparently, this changed in 3.5, I was looking at the 2.0 documentation...

How can I convert JavaScript code into one big Java string

So I have 1000 lines of javascript. I need to turn it into a Java String so that I can output (via System.out.println or whatever). I'm looking for an online tool to escape all the quotes... something geared toward my specific need would be nice as I don't want other special characters changed. Lines like: var rgx = /(\d+)(\d{3...

Replacing spaces with underscores in JavaScript?

I'm trying to use this code to replace spaces with _, it works for the first space in the string but all the other instances of spaces remain unchanged. Anybody know why? function updateKey() { var key=$("#title").val(); key=key.replace(" ","_"); $("#url_key").val(key); } ...

Return words before and after the first occurrence of a string

I have a body of text returned from a search query, lets call it $body. Now, what I want to do is for the script to find the first occurrence of the search query, $query. I know I can find this first occurrence this with strripos. Once found, I want the script to return a couple of words before the first occurrence of the string as ...

How to convert an unreadable string back to UTF-8 bytes in c#

I have a string looks like aeroport aimé I know it is French, and I want to convert this string back to readable format. Any suggestions? ...

How should I count the number of occurrences of a character at the beginning of a string in PHP

The best that I have been able to come up with is: strlen(preg_replace('/^([\\*]*)\s(.+)/',"$1",$line)); ^^That seems to give the length of the string.^^ edit: I think that I should clarify that the character that I am trying to find is '*' ...

How can I embed unicode string constants in a source file?

Hi all: I'm writing some unit tests which are going to verify our handling of various resources that use other character sets apart from the normal latin alphabet: Cyrilic, Hebrew etc. The problem I have is that I cannot find a way to embed the expectations in the test source file: here's an example of what I'm trying to do... /// //...

What could affect the lifespan of a NSString returned by stringWithContentsOfFile"?

Consider the 2 following methods of reading a string from a file: NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"]; NSString *string = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:NULL]; NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"]; NSFileH...