substring

substring on html.encode

how can I limit the # of characters to display for html.encode? <%= Html.Encode(item.LastName.Substring(1,30))%> error: Index and length must refer to a location within the string. ...

Why doesn't Google offer partial search? Is it because the index would be too large?

Google/GMail/etc. doesn't offer partial or prefix search (e.g. stuff*) though it could be very useful. Often I don't find a mail in GMail, because I don't remember the exact expression. I know there is stemming and such, but it's not the same, especially if we talk about languages other than English. Why doesn't Google add such a featu...

Finding a substring of multiple occurences in a string [C++]

Hi, is there any STL algorithm or a standard way of finding how many occurences of particular substring are there in a string? For example in string: 'How do you do at ou' the string "ou" appears twice. I tried some STL algorithms with and without predicates but what I found is that those algorithms from STL want to compare components...

Substring test within DataTable.Select()

I have a DataTable with results already pulled down from a back end. I want to do a DataTable.Select(), but the criteria is based on a SUBSTRING of one of the columns. Is there syntax to use in the Select() method that allows for substring of a column test, or do I have to do it the hard way -- scan each row. ...

How do I check if a C++ <string> starts with a certain string, and convert a substring to an int?

How do I do the following (Python pseudocode) in C++? if argv[1].startswith('--foo='): foo_value = int(argv[1][len('--foo='):]) (For example, if argv[1] is '--foo=98', then foo_value is 98.) Update: I'm hesitant to look into Boost, since I'm just looking at making a very small change to a simple little command-line tool. (I'd ra...

Find the nth occurrence of substring in a string

This seems like it should be pretty trivial, but I am new at Python and want to do it the most Pythonic way. I want to find the n'th occurrence of a substring in a string. There's got to be something equivalent to what I WANT to do which is mystring.find("substring", 2nd) How can you achieve this in Python? ...

Find the longest common starting substring in a set of strings

This is a challenge to come up with the most elegant JavaScript, Ruby or other solution to a relatively trivial problem. This problem is a more specific case of the Longest common substring problem. I need to only find the longest common starting substring in an array. This greatly simplifies the problem. For example, the longest subst...

jquery - get part of path?

I have a url that looks like this : http://mysite.com/1/2/Simpson and I want to create a variable that contains just Simpson... Not sure how to do it here... I have: var myvar = window.location.pathname and have tried something using substring, but can't seem to get it to work? ...

PHP substring extraction. Get the string before the first '/' or the whole string

I am trying to extract a substring. I need some help with doing it in PHP. Here are some sample strings I am working with and the results I need: home/cat1/subcat2 => home test/cat2 => test startpage => startpage I want to get the string till the first /, but if no / is present, get the whole string. I tried, substr($mystring, 0...

auto-tokenize user agents strings for statistics?

We keep track of user agent strings in our website. I want to do some statistics on them, to see how many IE6 users we have ( so we know what we have to develop against), and also how many mobile users we have. So we have log entires like this: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; FunWebProducts) Mozilla/4.0 (compatible; ...

How to get subString of a page of a long NSString, font size variable?

I have a very long text, I defined it as NSString, so I need paging, there will be different paging for different fonts, say I'd like to display one page on a multiple line UILabel. So at frist I need to get substring of page by page of the long string. Does anyone know good solution for this? Thanks in advance. I know there is a NSStr...

Select substring based on a string of options.

I have the following code // this text box can contain a URL such as: // http://vimeo.com/ // http://www.youtube.com/ // and so on. var text = $('#myTextBox').val(); var providers = "youtube|flickr|viddler|qik|revision3|hulu|vimeo"; if( text.match(providers).length > -1) { var selectedProvider = ???; } the match method looks i...

Getting the first character of a string with $str[0]

I want to get the first letter of a string and I've noticed that $str[0] works great. I am just not sure whether this is 'good practice', as that notation is generally used with arrays. This feature doesn't seem to be very well documented so I'm turning to you guys to tell me if it's all right in all respects to use this notation? Or ...

grabbing a subtring in a batch file

I am trying to automate DNS zone creation by using a batch file fired through one of Plesk's events. Using the dnscmd command, the batch checks to see if the zone exists. If the zone does not exist, the script adds it according to specs. If it does exist, and it is a secondary zone, the script deletes and recreates it according to s...

javascript substring

the most darndest thing! the following code prints out 'llo' instead of the expected 'wo'. i get such surprising results for a few other numbers. what am i missing here? alert('helloworld'.substring(5, 2)); ...

Java and substring

Hello, I need something simmilar to "awk { print $1 }", but for java. I have a string, similar to this: word1 word2 word3 word4 word5 word6 How, can I substring first word, from every line? ...

Output first two paragraphs from html stored as string

Hi, I have html stored in a string variable within my c# .net 2.0 code. Below is an example: <div class="track"> <img alt="" src="http://hits.guardian.co.uk/b/ss/guardiangu-feeds/1/H.20.3/30561?ns=guardian&amp;pageName=Hundreds+feared+dead+in+Haiti+quake%3AArticle%3A1336252&amp;ch=World+news&amp;c3=GU.co.uk&amp;c4=Haiti+%28News%29%...

SQL Server, T-SQL is there a faster way to substring the following string in my question?

I have strings like OPEN SYSTEMS SUB GR (GM/BTIB(1111)/BTITDBL(2222)/BTVY(4444)/ACSVTYSAG) in my database under my GROUPS Column. What I want to do is to extract the 2222 from that string. The code I am using is like that. SELECT SUBSTRING(GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS,0)+1)+1...

How to get the sub-string lying in between two sub-strings in C ?

I have a packet capture code that writes http payload into a file. Now i want to extract the URL information from these dumps. For each packet , the payload begins like this. GET /intl/en_com/images/logo_plain.png HTTP/1.1..Host: www.google.co.in..User-Agent: Mozilla/5.0 I would like to extract : the string between "GET" an...

Delete a matching substring ignore whitespaces

Hi , I need to delete a matching substring when found in string 1 ignoring whitespaces and charcters like -. The example I have is: string 1="The LawyerWhat happened to A&O's first female partner?The LawyerWhen Clare Maurice was made up at Allen & Overy (A&O) in 1985 she was the sole female partner at the firm. Twenty-five years later...