string

Should I use a concatenation of my string fields as a hash code?

I have an Address class in C# that looks like this: public class Address { public string StreetAddress { get; set; } public string RuralRoute { get; set; } public string City { get; set; } public string Province { get; set; } public string Country { get; set; } public string PostalCode { get; set; } }...

Multiplying strings in C#

Possible Duplicate: Can I "multiply" a string (in C#)? Exact duplicate of Can I “multiply” a string (in C#)? In Python I can do this: >>> i = 3 >>> 'hello' * i 'hellohellohello' How can I multiply strings in C# similarly to in Python? I could easily do it in a for loop but that gets tedious and non-expressive. Ultimately I...

Removing starting spaces in Python?

I have a text string that starts with a number of spaces, varying between 2 & 4. What's the easiest & simplest way to remove them ie. remove everything before a certain character? Cheers! ...

Split CSV String

How would I split the following string? test, 7535, '1,830,000', '5,000,000' The result should be test 7535 '1,830,000' '5,000,000' I try: Dim S() as string = mystring.split(",") But I get, test 7535 '1 830 000' '5 000 000' Thanks ...

fastest way to replace string in a template

I have some template string this is my {0} template {1} string which I plan to put user values in using String.Format(). The string actually is longer so for readability I use: this is my {goodName1} template {goodName2} string And then String.Replace each parameter with its value. How can I get the highest performance and ...

Ruby: create a String from bytes

I would like to build a string from a byte value. I currently use: str = " " str[0] = byte This seems to work fine but I find it ugly and not very scalable to strings longer than 1 character. Any idea? ...

How to use replace when making one variable = two others instead of just one

Okay this one might be a little tougher. I'm using VB that looks like this: string = Replace(string.ToLower, chr(63), "A") But I also want chr(63) = "B" as well, like this: string = Replace(string.ToLower, chr(63), "B") My problem is that when chr(63) is at the end of a string I need it to be B, and when it's not the end I need it...

Java string - get everything between (but not including) two regular expressions?

In Java, is there a simple way to extract a substring by specifying the regular expression delimiters on either side, without including the delimiters in the final substring? For example, if I have a string like this: <row><column>Header text</column></row> what is the easiest way to extract the substring: Header text Please note ...

Java - how to match regex Pattern containing single quotes?

[EDITED - really sorry, the code I quoted was wrong - have changed the message below to reflect this. Apologies! Thank you for your patience.] I'm new to regular expressions and want to match a pattern in Java (following on from this solution - http://stackoverflow.com/questions/962122/java-string-get-everything-between-but-not-includi...

Converting inserted string to a compilable expression

Hi, I'm somehow new to Java so my question can seem trivial, however i cannot find an answer to it anywhere in my books. I want to initiatie a dialog with a user in which he would enter an arithmetic expression (ex. (2*x+y)) And then print out the result for such expression (for given values of x and y) String EXPRESION = null; E...

dynamic string formatting using string.format and List<T>.Count()

I have to print out some PDFs for a project at work. Is there way to provide dynamic padding, IE. not using a code hard-coded in the format string. But instead based on the count of a List. Ex. If my list is 1000 elements long, I want to have this: Part_0001_Filename.pdf... Part_1000_Filename.pdf And if my list is say 500 elements ...

Processing a string in php

I have a really long string in a certain pattern such as userAccountName: abc userCompany: xyz userEmail: [email protected] userAddress1: userAddress2: userAddress3: userTown: .....and so on. This pattern repeats. I need to find a way to process this string so that I have the values of userAccountName:, userCompany: etc. (i.e. preferably in a...

Why don't popular programming languages use some other character to delimit strings?

Every programming language I know (Perl, Javascript, PHP, Python, ASP, ActionScript, Commodore Basic) uses single and double quotes to delimit strings. This creates the ongoing situation of having to go to great lengths to treat quotes correctly, since the quote is extremely common in the contents of strings. Why do programming languag...

How can I get the text from a component in a JList?

I have a JList and I am wanting to get the text of an entry of that list at a specific index. Could someone inform me how to do this or should I restructure my code to getValues instead of getIndices? ...

Show new lines from text area in ASP.NET MVC

Hi, I'm currently creating an application using ASP.NET MVC. I got some user input inside a textarea and I want to show this text with <br />s instead of newlines. In PHP there's a function called nl2br, that does exactly this. I searched the web for equivalents in ASP.NET/C#, but didn't find a solution that works for me. The fist one ...

Trimming blank spaces from a char array in C

My char array would be looking something like below, Org_arr[1first line text------2second line text----3third line-------4--------------------5fith line text------]; where '-' equal to blank spaces The above array contains the control code(0, 1, 2, 3..) after every 20 characters starting from 0-th place. I would like to convert th...

Use of object vs string vs enum

Hi! I have a situation that may seem ridiculus but I have not been able to figure out a good enough solution. To simplify things the problem is something like this, suppose you have an object like Manufacturer that has a countryname property (like car.Manufacturer.CountryName) and you want to be sure that the countryname property can no...

string splitting

i have a string: e.g. WORD1_WORD2_WORD3 how do i get just WORD1 from the string? i.e the text before the first underscore ...

After stripping unwanted tags, what else should I do to text input?

In a PHP script I'm accepting input from the user from a textarea and want to allow a few basic tags. So when I output the string I'm using - echo strip_tags($content, '<b><i><ul><ol><li>'); Now normally I would use FILTER_SANITIZE_STRING but that would strip all tags and I would use html_entities() but that would prevent the tags I'm...

Is there any benefit to using char instead of string for single-character values?

For .NET fields and properties that by definition only contain a single character, is there any benefit to defining them as char instead of string? Or is that an incorrect use of the char data type? I'm thinking of a field that can hold an M or F for sex, or a middle initial, or an indicator stored in the database as a Y or N. I typical...