string

Standard way to embed version into python package?

Hey everyone, Is there a standard way to associate version string with a python package in such way that I could do the following? import foo print foo.version I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in setup.py already. Alternative solution that I f...

Is there a builtin "hash to string" in Perl?

I'm coming to learn Perl from a Python background where the following hash-to-string conversion is built in to the language: >>> d = {'a': 1, 'b': 2, 'c': 3} >>> str(d) "{'a': 1, 'c': 3, 'b': 2}" Is there a builtin and/or module that has a subroutine with output along the lines of: "('a' => 1, 'b' => 2, 'c' => 3)" Strangely, a web ...

Creating indented text with bash

Hello. I want to print a list to screen in a readable way. I use a loop to go through each element and make a new list which is formatted with commas and newlines. The problem is that in the first line of the output, I want a title. E.g., I want to print something like this: List: red, green, blue, black, cars, busses, ... The p...

String length differs from Javascript to Java code

I've got a JSP page with a piece of Javascript validation code which limits to a certain amount of characters on submit. I'm using a <textarea> so I can't simply use a length attribute like in a <input type="text">. I use document.getElementById("text").value.length to get the string length. I'm running Firefox 3.0 on Windows (but I've ...

Quickie - replace all occurences of ' (apostrophe) with '' (two apostrophes) in an AnsiString (C++)

I think you can guess the problem I'm having. I'm inserting filenames in to an sql database in C++ Builder. Some files have an apostrophe in their name. This breaks the sql insert query. the usual way to fix this is to double up and apostrophes you want to be part of the field value. For example if I want to add 'george's' to field ...

Use of the String(String) constructor in Java

I've read on articles and books that the use of String s = new String("..."); should be avoided pretty much all the time. I understand why that is, but is there any use for using the String(String) constructor whatsoever? I don't think there is, and don't see any evidence otherwise, but I'm wondering if anyone in the SO commmunity know...

Can I be sure the built-in hash for a given string is always the same?

I am getting a string hash like this: string content = "a very long string"; int contentHash = content.GetHashCode(); I am then storing the hash into a dictionary as key mapping to another ID. This is useful so I don't have to compare big strings during default dictionary hash computation but I can just fish the ID from the dictionary...

Separating 'body' of domain name from extension - DOS shell

Hi, I tried everything possible, but still failed. I thought I got it at the point which I'll post as my final attempt, but still isn't good [enough]. A script is being passed three arguments. Domain name, username and password. But the probles is that I need domain separated in "domain" + ".com" format. Two variables. I tried to split...

Using a Boolean Expression in a StringBuilder

I'm using a string builder to build some SQL Scripts. I have a few Boolean Properties that I would like to test and then output different text based on true/false. I've you the C# syntax below when assigning a value to a variable, but it isn't working for this particular situation. Any ideas? What I'm used to doing: string someText ...

What is the best way to extract load average float values from a string in Python?

If I have a string such as "17:31:51 up 134 days, 11:26, 1 user, load average: 0.22, 0.15, 0.10" what is the best way to extract just the x3 load average values at the end? I have written a regexp that does this but is this the most efficient / fastest method? >>> s = "17:31:51 up 134 days, 11:26, 1 user, load average: 0.22, 0.15,...

C string initializer doesn't include terminator?

I am a little confused by the following C code snippets: printf("Peter string is %d bytes\n", sizeof("Peter")); // Peter string is 6 bytes This tells me that when C compiles a string in double quotes, it will automatically add an extra byte for the null terminator. printf("Hello '%s'\n", "Peter"); The printf function knows when to ...

.NET String to byte Array C#

How do I convert a string to a byte array in .NET (C#)? Update: Also please explain why encoding should be taken into consideration. Can't I simply get what bytes the string has been stored in? Why this dependency on encoding?!!! ...

String Benchmarks in C# - Refactoring for Speed/Maintainability

I've been tinkering with small functions on my own time, trying to find ways to refactor them (I recently read Martin Fowler's book Refactoring: Improving the Design of Existing Code). I found the following function MakeNiceString() while updating another part of the codebase near it, and it looked like a good candidate to mess with. A...

Ruby string mutability

This may be a bit of a nooby question, I have been trying to get better at ruby recently, and started reading the fantastic The Ruby Programming Language. Something that was mentioned is that string literals are considered mutable, so in a loop it is better to use a variable then a literal, as a new string will get instantiated at every ...

Word comparison algorithm

I am doing a CSV Import tool for the project I'm working on. The client needs to be able to enter the data in excel, export them as CSV and upload them to the database. For example I have this CSV record: 1, John Doe, ACME Comapny (the typo is on purpose) Of course, the companies are kept in a separate table and linked with...

What's the best way to trim whitespace from a string in Cocoa Touch?

I'm looking to determine whether a string value from a user input (UITextField) is "blank" if it's not nil. Checking if [textField.text isEqualToString:""] isn't quite enough because I want to avoid any blank/whitespace input (like say a few space characters). There does seem to be an indication of a good solution for my particular pro...

ASP.NET Could not load type 'System.String'

Has anyone ever seen an issue with an ASP.NET websuite blows up on initial login, complaining about a system.string type in the profile that is defined in the web.config. More Info: Server Error in '/abc' Application. -------------------------------------------------------------------------------- Configuration Error Description: An ...

ASP.NET Could not load type 'System.String'

System.Configuration.ConfigurationErrorsException: Attempting to load this property's type resulted in the following error: Could not load type 'System.String'. (D:\Inetpub\wwwroot\driverseat\web.config line 223) ---> System.Web.HttpException: Could not load type 'System.String'. at System.Web.Compilation.BuildManager.GetType(String typ...

Is CultureInfo.CurrentCulture really necessary in String.Format() ?

Hi. How do you think is really necessary to provide IFormatProvider in method String.Format(string, object) ? Is it better to write full variant String.Format(CultureInfo.CurrentCulture, "String is {0}", str) or just String.Format("String is {0}", str) ? ...

python string join performance

There are a lot of articles around the web concerning python performance, the first thing you read: concatenating strings should not be done using '+': avoid s1+s2+s3, instead use str.join I tried the following: concatenating two strings as part of a directory path: three approaches: '+' which i should not do str.join os.path.join H...