string-manipulation

What does the offset word mean in the context of programming?

Hello What does the offset word mean in the context of programming? does mean in the beginning or by a distance. what does string.offsetByCodePoints(int index, int codePointOffset) method exactly do? And what do they mean in the documentation by Unpaired surrogates? Thanks in advance for your help ...

Substring indexes off in simple map reading program

Alright, so I'm trying to create a simple RPG game, and my map reading code seems to be off. This is the map reading line: Integer.parseInt(map.data.substring(Map.MAP_START + ((playerPOS - map.width)/2) - 1, Map.MAP_START + ((((playerPOS - map.width)/2) - 1) + map.dataLen))); Now the only tiles in the map are 01 and 00, so when I see ...

MySql : Break string by delimiters (^A)

I have a string that is of the: type 'field1^Afield2^Afield3^A' I need to break this string and get one of the fields. All the string functions I see in MySql that help you break by delimiter expect a string as the delimiter , example: SUBSTRING_INDEX("Hello. Break this. for me", ".", 1) would give = "Hello" How do i break mu string...

Linq & String.ToLower() strange behavior

Hi! I have a query on the server side that returns a list of distinct cities from a zipcode table. I'm using WCF RIA Service. The following query successfully returns 228 cities when provincename == "" public IQueryable<CityPM> GetCities(string provinceName) { return this.ObjectContext.ZipCodes.Where(z => z.Province.Cont...

how to use sscanf in loops?

Is there a good way to loop over a string with sscanf? Let's say I have a string that looks like this: char line[] = "100 185 400 11 1000"; and I'd like to print the sum. What I'd really like to write is this: int n, sum = 0; while (1 == sscanf(line, " %d", &n)) { sum += n; line += <number of bytes consumed by sscanf> } but t...

SQLite equivalent of Python's "'%s %s' % (first_string, second_string)"

As the title says, what is the equivalent of Python's '%s %s' % (first_string, second_string) in SQLite? I know I can do concatenation like first_string || " " || second_string, but it looks very ugly. ...

How to find nth occurrence of character in a string?

Similar to a question posted here, am looking for a solution in Java. That is, how to find the index of nth occurrence of a character/string from a string? Example: "/folder1/folder2/folder3/". In this case, if I ask for 3rd occurrence of slash (/), it appears before folder3, and I expect to return this index position. My actual inte...

Javascript: How to extract multiple numbers from a string

Input: "NEW YORK (Reuters) U.S. stock index futures pointed to a slight rebound on Wall Street on Wednesday, with futures for the S&P 500 up 0.34 percent, Dow Jones futures up 0.12 percent and Nasdaq 100 futures up 0.51 percent at 0921 GMT." Output should be array of all numbers including floats. A little similar thread but it ex...

Java - convert String (EEST included) into date

I'm having this kind of String: Wed Oct 27 00:00:00 EEST 2010 and I want to parse this into type Date. I've tried with DateTimeFormat fmt = DateTimeFormat.getFormat("EEE MMM dd HH:mm:ss zzzz yyyy"); but it doesn't work. Need help in getting this fixed. Thanks. ...

Regular Expressions - testing if a String contains another String

Suppose you have some this String (one line) 10.254.254.28 - - [06/Aug/2007:00:12:20 -0700] "GET /keyser/22300/ HTTP/1.0" 302 528 "-" "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" and you want to extract the part between the GET and HTTP (i.e., some url) but only if it contain...

How do I concatenate strings with variables in powershell?

I'm trying to build a file path in powershell and the string concatenation seems to be a little funky. I have a list of folders: c:\code\MyProj1 c:\code\MyProj2 I want to get the path to a dll here: c:\code\MyProj1\bin\debug\MyProj1.dll c:\code\MyProj2\bin\debug\MyProj2.dll Here's what I'm trying to do: $buildconfig = "Debug" G...

C# Replace wildcard

I am making an application to change the the resolution of that game, to the requested resolution. StreamReader reader = new StreamReader(@"C:\Documents and Settings\ARTech\Bureaublad\PersistentSymbols.ini");//Reads the file. string content = reader.ReadToEnd();//Puts the content of the file, into a variable. reader.Close(); string repl...

Negative lookbehind in Python regular expressions

Hey, I am trying to parse a list of data out of a file using python - however I don't want to extract any data that is commented out. An example of the way the data is structured is: #commented out block uncommented block # commented block I am trying to only retrieve the middle item, so am trying to exclude the items with hashes a...

update sql column with same data but with a little modifications to it

I have a sql DB table columns which carries data in "0000-00-0000" format. For ex: "8753-11-2010" Now i need to change this value from "8753-11-2010" to "008753-0011-2010" i.e. i need to pad "00" in front of "8753" and "11" i mean the first two strings u can call it. please advise how i can achieve this in sql server 2005. I need to ...

When accessing individual characters in a string in Perl, is substr or splitting to an array faster?

I'm writing a Perl script in which I need to loop over each character of a string. There's a lot of strings, and each is 100 characters long (they're short DNA sequences, in case you're wondering). So, is it faster to use substr to extract each character one at a time, or is it faster to split the string into an array and then iterate o...

Add spaces between words in spaceless string

I'm on OS X, and in objective-c I'm trying to convert for example, "Bobateagreenapple" into "Bob ate a green apple" Is there any way to do this efficiently? Would something involving a spell checker work? EDIT: Just some extra information: I'm attempting to build something that takes some misformatted text (for example, text copy ...

PHP code to generate safe URL?

We need to generate a unique URL from the title of a book - where the title can contain any character. How can we search-replace all the 'invalid' characters so that a valid and neat lookoing URL is generated? For instance: "The Great Book of PHP" www.mysite.com/book/12345/the-great-book-of-php "The Greatest !@#$ Book of PHP" www.my...

how to remove new lines and returns from php string?

A php variable contains the following string: <p>text</p> <p>text2</p> <ul> <li>item1</li> <li>item2</li> </ul> I want to remove all the new line characters in this string so the string will look like this: <p>text</p><p>text2><ul><li>item1</li><li>item2</li></ul> I've tried the following without success: str_replace('\n', '', $st...

how to find all the words starting with '$' sign and ending with space, in a long string

In C#, how do I find all the words starting with '$' sign and ending with space, in a long string, using Regular expressions? ...

Reading a string line per line in C#

Hi, I'm trying to read out and interpret a string line per line. I took a look at the StringReader class, but I need to find out when I'm on the last line. Here's some pseudocode of what I'm trying to accomplish: while (!stringReaderObject.atEndOfStream()) { interpret(stringReaderObject.readLine()); } Does somebody know how to do...