string-manipulation

Repeated regular expression

How can I parse a strings like : name1="val1" name2="val2" name3="val3" I cannot use split(\s+) as it can be name = "val 1". I am doing java but any laguage is okay. ...

How do I prevent buffer overflow converting a double to char?

I'm converting a double to a char string: char txt[10]; double num; num = 45.344322345 sprintf(txt, "%.1f", num); and using ".1f" to truncate the decimal places, to the tenths digit. i.e. - txt contains 45.3 I usually use precision in sprintf to ensure the char buffer is not overflowed. How can I do that here also truncating the de...

Formatting an integer in C++

I have an 8 digit integer which I would like to print formatted like this: XXX-XX-XXX I would like to use a function that takes an int and returns a string. What's a good way to do this? ...

How can I remove certain characters from inside angle-brackets, leaving the characters outside alone?

Edit: To be clear, please understand that I am not using Regex to parse the html, that's crazy talk! I'm simply wanting to clean up a messy string of html so it will parse Edit #2: I should also point out that the control character I'm using is a special unicode character - it's not something that would ever be used in a proper tag unde...

C++ String tokenisation from 3D .obj files

I'm pretty new to C++ and was looking for a good way to pull the data out of this line. A sample line that I might need to tokenise is f 11/65/11 16/70/16 17/69/17 I have a tokenisation method that splits strings into a vector as delimited by a string which may be useful static void Tokenise(const string& str, vector<string>& tokens,...

Jquery convert string of one type to string array.....

Consider a string which is {"Table" : [{"Bird" : "Peacock"}, {"Bird" : "Crow"}]} to this ["Peacock", "Crow"] in jquery... Is this possible? EDIT: I am doing this but didnt work... $(document).ready(function() { var obj = JSON.parse('{"Table" : [{"Bird" : "Peacock"},{"Bird" : "Crow"}]}'); myarray = []...

Java split is eating my characters.

Hi, I have a string like this String str = "la$le\\$li$lo". I want to split it to get the following output "la","le\\$li","lo". The \$ is a $ escaped so it should be left in the output. But when I do str.split("[^\\\\]\\$") y get "l","le\\$l","lo". From what I get my regex is matching a$ and i$ and removing then. Any idea of how to g...

How do you tell if two wildcards overlap?

Given two strings with * wildcards, I would like to know if a string could be created that would match both. For example, these two are a simple case of overlap: Hello*World Hel* But so are all of these: *.csv reports*.csv reportsdump.csv Is there an algorithm published for doing this? Or perhaps a utility function in Windows or...

Working with edit distance and then processing the results to find chunks / groups

Hi, After processing a dictionary of words I have edit distances (or rather similarity in percent) saved in a data structure, kinda like this: s1=String1, s2=String2, similarity=82 s1=String2, s2=String3, similarity=82 s1=aaaaaaa, s2=aaaaaab, similarity=90 s1=aaaaaaa, s2=aaaaaac, similarity=95 My aim is to have a list of groups of simi...

XSL split string using empty elements

Let's say I have a line in an XML file like the following (derived from an HTML file): <i>This is a nice poem<br/>It doesn't rhyme<br/>because right now<br/>I don't have time</i> I am attempting to right an XSLT to split this string with the following output: <stanza> <line>This is a nice poem</line> <line>It doesn't rhyme</l...

What is the best way to remove multiple occurences of a character in a string in java

I have a string like foo..txt and I want to convert it to foo.txt The occurence of '.' may be more than 2 also. What is the best way to accomplish this? edit : The '.' may not occur just together. The occurences may be as below too foo.bar.txt = foo bar.txt foo..bar.foo.txt = foo bar.txt ...

PHP: filter string to work as a function name

what is a quick way to filter a string to work as a function name? note: I'm thinking something like filter_var(). ...

if (str1 == null) when throws a NullPointerException

In java, Does the following line have a possibility (even 0.01%) to throw a NullPointerException?? public static void handleRequest(String str1){ if (str1 == null){ // this line throws NPE, how come !! is it a JDK1.5 bug!! return null; } // other staff } Actually I am falling some bug in the code and It says that the...

Number of simple mutations to change one string to another?

Hi; I'm sure you've all heard of the "Word game", where you try to change one word to another by changing one letter at a time, and only going through valid English words. I'm trying to implement an A* Algorithm to solve it (just to flesh out my understanding of A*) and one of the things that is needed is a minimum-distance heuristic. ...

How can I modify the directory in a Perl string that has a file path?

I have a string that has a file path: $workingFile = '/var/tmp/A/B/filename.log.timestamps.etc'; I want to change the directory path, using two variables to note the old path portion and the new path portion: $dir = '/var/tmp'; $newDir = '/users/asdf'; I'd like to get the following: '/users/asdf/A/B/filename.log.timestamps.etc' ...

Replace string with incremented value

Hello, I'm trying to write a CSS parser to automatically dispatch URLs in background images to different subdomains in order to parallelize downloads. Basically, I want to replace things like url(/assets/some-background-image.png) with url(http://assets[increment].domain.com/assets/some-background-image.png) I'm using this insid...

VB.NET one dimensional string array manipulation difficulty

I am having some problems with manipulating a one dimensional string array in VB.NET and would like your assistance please. My objective is to get 4 variables (if possible) from a file path. These variables are: myCountry, myCity, myStreet, Filename. All declared as string. The file location is also declared as string. so I have: Dim f...

increasing string size through loop

what's a simple way to increase the length of a string to an arbitrary integer x? like 'a' goes to 'z' and then goes to 'aa' to 'zz' to 'aaa', etc. ...

Print one word from a string in python

Hi, How can i print only certain words from a string in python ? lets say i want to print only the 3rd word (which is a number) and the 10th one while the text length may be different each time mystring = "You have 15 new messages and the size is 32000" thanks. ...

something like a python's triple-quote in F# (or C#)?

I want to assign a xml code into a string variable. I can do this without escaping single or double-quotes by using triple-quote in python. Is there a similar way to do this in F# or C#? ...