string

Find largest cluster of a particular word in a block of text

I have a block of text (of arbitrary length) with a particular word highlighted in yellow whenever it appears. I want to show only a 400 word chunk of the text but I want to show the chunk with the most highlighted words. Does anyone know a good algorithm for this? I have the character position of each highlighted word, so the algorith...

[XSLT] Test for a value inside a string

Let's say I have the string of "2004,2005,2006,2007,2008,2009" that is assigned to the parameter of "show". Now, this does work: <xsl:if test="$show='2004'"> //stuff </xsl:if> This doesn't work: <xsl:if test="$show='2005'"> //stuff </xsl:if> I'm not sure how to test for part of a string like that. Any idea? ...

Fastest way to find minimal Hamming distance to any substring?

Given a long string L and a shorter string S (the constraint is that L.length must be >= S.length), I want to find the minimum Hamming distance between S and any substring of L with length equal to S.length. Let's call the function for this minHamming(). For example, minHamming(ABCDEFGHIJ, CDEFGG) == 1. minHamming(ABCDEFGHIJ, BCDGHI...

Javascript String Library

I'm using Jquery for DOM manipulation, and I'm finding it invaluable. Is there a similar library for strings? I find myself needing to do manipulations and running selectors on parts of strings, and I just wish I can apply jquery syntax to it. Anyone know of anything like that? Ideally I would use a syntax like this: var select = $(...

Get a URL from a String

For a little while now I've been searching for a code to get URL's out of a string using PHP. I'm basically trying to get a Shortened URL out of a message, and then later do a HEAD request to find the actual link. Anyone have any code that returns URLs from strings? Thanks in advanced. Edit for Ghost Dog: Here is a sample of what I...

UIWebView loading parsed html string

Hello, i'm building an app that will display some newsletters to the users. the newsletters are displayed in a uiWebView. I'm reading the url's for the newsletters from an rss feed. I parse the xml, and in a table view i have all the newsletters. When a cell is clicked the uiWebView is pushed and the newsletter is loaded. Because the uiW...

How can i create a variable with dynamic name?

I'm working on c#. I want to create a var in a for loop, e.g. for(int i; i<=10;i++) { string s+i = "abc"; } ...

getting error not all code paths return value by c# compiler

This is a basic string reverse program and I want to do some level of exception handling in it. But during compilation it gives me an error "NOt all code paths return value. I am not able to find out why public static string Reverse(string s) { try { if (string.IsNullOrEmpty(s)) ...

TrimTrailingBlanks in SQL Server

In sp_help documentation doesn't says much about the property TrimTrailingBlanks of a table: TrimTrailingBlanks | varchar(35) | Trim the trailing blanks. Returns Yes or No. so I'm thinking if is good practice to turn it on or if I should let it's default off. What I want to do is to delete blanks from left and right strings, and (by t...

Why does a quoted string match bool method signature before a std::string?

Given the following methods: // Method 1 void add(const std::string& header, bool replace); //Method 2 void add(const std::string& name, const std::string& value); It would appear that the following code will end up calling method 1 instead of method 2: something.add("Hello", "World"); I ended up creating another method that looks...

concatenate string to char in C#

I need to concatenate '*', which is a string, to a character in an array. For example: int count=5; string asterisk="*"; char p[0]='a'; char p[1]='b'; char p[2]='a'; char p[3]='b'; char p[4]='b'; for(int i=0;i<count;i++) { asterisk=asterisk+"*"; } p[0]=p[0]+asterisk; How can I do this? I want the result to be li...

A question regarding string instance uniqueness in python

I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code: A = "10000" B = "10000" C = "100" + "00" D = "%i"%10000 E = str(100...

Why doesn't C terminate strings with a special escaped string-termination character?

In C, strings are terminated with null ( \0 ) which causes problems when you want to put a null in a strings. Why not have a special escaped character such as \$ or something? I am fully aware at how dumb this question is, but I was curious. ...

Fast string comparison with list

I need a fast method to determine if a given string is in a list of strings. The list of strings is not known until runtime but thereafter it will not change. I could simply have a List<String> called strings and then do: if (strings.Contains(item)) However this will perform poorly if there are many strings in the list. I could als...

Simple python / Beautiful Soup type question

I'm trying to do some simple string manipulation with the href attribute of a hyperlink extracted using Beautiful Soup: from BeautifulSoup import BeautifulSoup soup = BeautifulSoup('<a href="http://www.some-site.com/"&gt;Some Hyperlink</a>') href = soup.find("a")["href"] print href print href[href.indexOf('/'):] All I get is: Traceba...

How to remove particular characters from a string using XSLT?

Hi, I need to check if a particular string contains a a particular word for example to check if, SultansOfSwing contains the word Swing. Let me also mention that the value of the string in question is unknown. As in it can be any word so we do not know the length et cetera. I understand I can do this by using the contains keyword. Bu...

Bug trying to add two strings with snprintf

I'm trying to add two strings with snprintf but apparently i dont know what i'm doing. Here is the code block: char * filename = NULL; (void)snprintf (filename, sizeof(filename), "%s/%s", PATH, FILE); I also tried: char * filename = NULL; (void)snprintf (filename, sizeof(PATH)+sizeof(FILE)+1, "%s/%s", PATH, FILE); PATH...

Java String contain function?

from the following strings: "details.php?news=13&action=main&menu_type=&option=single&news_id=4792&pub_no=50" Is this possible in String str.contains(strcase) where strcase="details.php", "news_id" can both be checked at the same time. Not like: str.contains("details.php")&&str.contains("news_id"). both cases should be taken to t...

Count occurrence of a character in a Python string

What's the simplest way to count the number of occurrences of a character in a string? e.g. count the number of times 'a' appears in 'Mary had a little lamb' ...

regular expression question

I want to replace the question mark (?) in a string with some other words. What is the regular expression for question mark. For example, I want to replace question mark in "word=?" to something else, say "stackoverflow". Then the result would be "word=stackoverflow". What is the syntax in java? ...