string-manipulation

Python: Nicest way to pad zeroes to string

What is the nicest/shortest way to pad a string with zeroes to the left, so the string length has a specific length? ...

How to increment a java String through all the possibilities?

I need to increment a String in java from "aaaaaaaa" to "aaaaaab" to "aaaaaac" up through the alphabet, then eventually to "aaaaaaba" to "aaaaaabb" etc. etc. Is there a trick for this? ...

Bash string handling (char at index and concatenation)

I'm trying to learn bash string handling. How do I create a bash script which is equivalent to this Java code snippet? String symbols = "abcdefg12345_"; for (char i : symbols.toCharArray()) { for (char j : symbols.toCharArray()) { System.out.println(new StringBuffer().append(i).append(j)); } } The output of the above code...

Best algorithm to strip leading and trailing spaces in C

What is the best approach in stripping leading and trailing spaces in C? ...

Capitalize a string

Hi, Does anyone know of a really simple way of capitalizing just the first letter of a string, regardless of the capitalization of the rest of the string? For example: asimpletest -> Asimpletest aSimpleTest -> ASimpleTest I would like to be able to do all string lengths as well. Thanks, Dan ...

RegEx to get text within tags

I need a Regular Expressions to get the text within 2 tags. Lets say I want an array returned containing any text within <data> and </data> tags. Or any text within "(" and ")" tags. How can I do that with RegEx's in C#? An advanced question would be: The input string is "color=rgb(50,20,30)" How can I get the 3 numbers in 3 sepe...

Most effective way to grab a table name in the following string

Hi, What would be the most effective way to grab the schema + table name in this scenario: SELECT [t0].[Id], [t0].[CODE] AS [arg0], [t0].[DESC] AS [arg1] FROM [SchemaName].[TableName] AS [t0] WHERE ([t0].[Id] <> @p0) The outcome needs to be: "SchemaName.TableName" .... I'm using C#. Thanks! ...

C# Extracting a name from a string

I want to extract 'James\, Brown' from the string below but I don't always know what the name will be. The comma is causing me some difficuly so what would you suggest to extract James\, Brown? OU=James\, Brown,OU=Test,DC=Internal,DC=Net Thanks ...

Render or convert Html to 'formatted' Text (.NET)

Hi, I'm importing some data from another test/bug tracking tool into tfs, and I would like to convert it's description, which is in simple HTML, so a plain string, where the 'layout' of the HTML is preserved. For example: <body> <ol> <li>Log on with user Acme &amp; Co.</li> <li>Navigate to the details tab</li> <li>Check ...

.NET: Is there a String.Format form for inserting the value of an object property into a string?

I think the direct answer to the question is 'No' but I'm hoping that someone has written a real simple library to do this (or I can do it...ugh...) Let me demonstrate what I am looking for with an example. Suppose I had the following: class Person { string Name {get; set;} int NumberOfCats {get; set;} DateTime TimeTheyWillDie {g...

When is it best to use Regular Expressions over basic string spliting / substring'ing?

It seems that the choice to use string parsing vs. regular expressions comes up on a regular basis for me anytime a situation arises that I need part of a string, information about said string, etc. The reason that this comes up is that we're evaluating a soap header's action, after it has been parsed into something manageable via the O...

Remove characters using Regex

I have a string. I need to replace all instances of a given array of strings from this original string - how would I do that? Currently I am using... var inputString = "this is my original string."; var replacement = ""; var pattern = string.Join("|", arrayOfStringsToRemove); Regex.Replace(inputString, pattern, replacement); This wo...

Cleanest way to build an SQL string in Java

I want to build an SQL string to do database manipulation (updates, deletes, inserts, selects, that sort of thing) - instead of the awful string concat method using millions of "+"'s and quotes which is unreadable at best - there must be a better way. I did think of using MessageFormat - but its supposed to be used for user messages, ...

How would you attack this polymorphism string building problem.

Sorry for not so discrptive title, if someone wants to change it go ahead. Also note I have already asked a question about this kind of thing but this one is more about how you would attack it because my attack just doesn't seem to feel right. I am having a problem with building a string up to send to an OLE object in the correct order...

String concatenation vs. string substitution in Python

In Python, the where and when of using string concatenation versus string substitution eludes me. As the string concatenation has seen large boosts in performance, is this (becoming more) a stylistic decision rather than a practical one? For a concrete example, how should one handle construction of flexible URIs: DOMAIN = 'http://stack...

How do I extract a string of text that lies between two (brackets) using .NET?

I have a string "User name (sales)" and I want to extract the text between the brackets, how would I do this? I suspect substring but I can't work out how to read until the closing bracket, the length of text will vary. ...

Replacing accented/umlauted characters with their unadorned counterparts in C#

Duplicate of 249087 I have a bunch of user generated addresses that may contain characters with diacritic marks. What is the most effective (i.e. generic) way (apart from a straightforward replace) to automatically convert any such characters to their closest English equivalent? E.g. any of àâãäå would become a æ would become the tw...

Padding Strings in Java

Is there some easy way to pad Strings in Java. seems like something that should be in some stringUtil like api but i cant find any. ...

removing whitespaces in ActionScript 2 variables

let's say that I have an XML file containing this : <description><![CDATA[ <h2>lorem ipsum</h2> <p>some text</p> ]]></description> that I want to get and parse in ActionScript 2 as HTML text, and setting some CSS before displaying it. Problem is, Flash takes those whitespaces (line feed and tab) and display it as it is. <some...

Formatting text for a combobox, C#

I have three values I need to align in a dropdown box. How can I do this? I've been trying this: String.Format("{0,-30}{1,-15}{2,-10}{3,-8}", new object[] { cusJob, service, username, time }); But that leaves it uneven because it's not a monospaced font. I don't really want to use a monospaced font and I've seen applications align it b...