string-manipulation

Sprintf equivalent in Java

Printf got added to Java with the 1.5 release but I can't seem to find how to send the output to a string rather than a file (which is what sprintf does in C). Does anyone know how to do this? ...

Split out ints from string

Let's say I have a web page that currently accepts a single ID value via a url parameter: http://example.com/maypage.aspx?ID=1234 I want to change it to accept a list of ids, like this: http://example.com/mypage.aspx?IDs=1234,4321,6789 So it's available to my code as a string via context.Request.QueryString["IDs"]. What's the ...

C# string manipulation search and replace

I have a string which contain tags in the form < tag >. Is there an easy way for me to programmatically replace instances of these tags with special ascii characters? e.g. replace a tag like "< tab >" with the ascii equivelent of '/t'? ...

C# String ASCII representation

How can I insert ASCII special characters (e.g. with the ASCII value 0x01) into a string? I ask because I am using the following: str.Replace( "<TAG1>", Convert.ToChar(0x01).ToString() ); and I feel that there must be a better way than this. Any Ideas? Update: Also If I use this methodology, do I need to worry about unicode & ASCII...

Alternative to String.Replace

So I was writing some code today that basically looks like this: string returnString = s.Replace("!", " ") .Replace("@", " ") .Replace("#", " ") .Replace("$", " ") .Replace("%", " ") .Replace("^", " ") .Replace("*", " ") .Replace("_", " ") .R...

What is the LINQ way to implode/join a string array?

I have the following string array: var sa = new string[] {"yabba","dabba","doo"}; I can convert it to "yabba, dabba, doo" it using string.Join() but what is the super-cool LINQ way of doing it? The Join extension method seems promising but for a novice like me very confusing. ...

How do I remove the file suffix and path portion from a path string in Bash?

Given a string file path such as "/foo/fizzbuzz.bar" how would I use bash to extract just the "fizzbuzz" portion of said string? ...

What's the best way to remove <br> tags from the end of a string?

The .NET web system I'm working on allows the end user to input HTML formatted text in some situations. In some of those places, we want to leave all the tags, but strip off any trailing break tags (but leave any breaks inside the body of the text.) What's the best way to do this? (I can think of ways to do this, but I'm sure they're ...

How to remove accents and tilde in a C++ std::string

Hi everyone, I have a problem with a string in C++ which has several words in Spanish. This means that I have a lot of words with accents and tildes. I want to replace them for their not accented counterparts. Example: I want to replace this word: "había" for habia. I tried replace it directly but with replace method of string class but...

How to remove illegal characters from path and filenames?

I need a robust and simple way to remove illegal path and file characters from a simple string. I've used the below code but it doesn't seem to do anything, what am I missing? using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string illeg...

.NET - How can you split a "caps" delimited string into an array?

How do I go from this string: "ThisIsMyCapsDelimitedString" ...to this string: "This Is My Caps Delimited String" Fewest lines of code in VB.net is preferred but C# is also welcome. Cheers! ...

What is the simplest way to convert char[] to/from tchar[] in C/C++(ms)?

This seems like a pretty softball question, but I always have a hard time looking up this function because there seem there are so many variations regarding the referencing of char and tchar. ...

String.Format like functionality in T-SQL?

Hi, I'm looking for a built-in function/extended function in T-SQL for string manipulation similar to the String.Format method in .NET. ...

Language showdown: Convert string of digits to array of integers?

I was trying to convert a string containing only base 10 digits (e.g. "124890") to an array of corresponding integers (for given example: [1, 2, 4, 8, 9, 0]), in Ruby. I'm curious about how easily this can be accomplished in Ruby and in other languages. ...

Python find() and newlines

While editing someone else's abandoned Python script, I was trying to use mystring.find("\n", i) to get the index of the next newline in a string. But this consistently returns -1 (even when I try using "\r\n" instead of "\n"). I know there are newlines in the string, because I had just loaded it from a file. I am not very familiar wi...

Finding the end of a substring match in .NET

I am trying to find the index of a substring in a string that matches another string under a specific culture (provided from a System.CultureInfo). For example the string "ass" matches the substring "aß" in "straße" under a German culture. I can find the index of the start of the match using culture.CompareInfo.IndexOf(value, substr...

How can I do an indexOf() in Lotus Notes Formula language (@ commands)?

I can't find this anywhere in the Domino Designer help. It seems so straightforward! All I need to do is find the position of a character in a string. ...

Splitting a semicolon-separated string to a dictionary, in Python

I have a string that looks like this: "Name1=Value1;Name2=Value2;Name3=Value3" Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this: dict = { "Name1": "Value1", "Name2": "Value2", "Name3": "Value3" } I have looked through the modules available but ...

How can I split multiple joined words?

I have an array of 1000 or so entries, with examples below: wickedweather liquidweather driveourtrucks gocompact slimprojector I would like to be able to split these into their respective words, as: wicked weather liquid weather drive our trucks go compact slim projector I was hoping a regular expression my do the trick. But, sinc...

Swap every pair of characters in string

I'd like to get all the permutations of swapped characters pairs of a string. For example: Base string: abcd Combinations: bacd acbd abdc etc. What's the best way to do this? ...