substring

Python index more than once.

I know that .index() will return where a substring is located in python. However, what I want is to find where a substring is located for the nth time, which would work like this: >> s = 'abcdefacbdea' >> s.index('a') 0 >> s.nindex('a', 1) 6 >>s.nindex('a', 2) 11 Is there a way to do this in python? ...

Check if one column value is contained in another column value (TSQL)?

Hey, I have 2 tables with many columns and I want to find those rows where the value from table1.somecolumn is contained in table2.someothercolumn. Example: table1.somecolumn has Smith, Peter and table2.someothercolumn has peter.smith That should be a match, how would I do such a search? Thanks :) ...

Display only 10 characters of a long string?

How do I get a long text string (like a querystring) to display a maximum of 10 characters, using JQuery? Sorry guys I'm a novice at JavaScript & JQuery :S Any help would be greatly appreciated. ...

Search for (Very) Approximate Substrings in a Large Database

I am trying to search for long, approximate substrings in a large database. For example, a query could be a 1000 character substring that could differ from the match by a Levenshtein distance of several hundred edits. I have heard that indexed q-grams could do this, but I don't know the implementation details. I have also heard that L...

Substring search algorithms (very large haystack, small needle)

I know there are already several similar questions here, but I need some recommendations for my case (couldn't find anything similar). I have to search a very large amount of data for a substring that would be about a billion times smaller (10 bytes in 10 billion bytes). The haystack doesn't change, so I can bear with large precomputati...

Iphone substring causing memory leak

Hi All, Im just wrapping up my app, so im onto the stage of running instruments to identify leaks in the app. Ive come across a leak that I cannot work out why it is being registered as a leak. I have the following lines for example: NSString *imageType = [[[NSString alloc] initWithString:[loopString substringToIndex:[loopString rangeO...

How to strip the last part of a query string

Hi all, I need to isolate an id in a string using javascript. I've managed to get to the part where I get to the id but then I want to be able to string the rest of the string so that it only leaves the id number such as this: var urlString = "http://mysite.co.za/wine/wine-blog/blogid/24/parentblogid/15.aspx"; // if the blogid ...

SQL: Finding duplicate values in a field, but using SubString()

Here's a question for all those SQL SERVER 2000 experts: I have only 1 table... I can already find if any of the values in a certain field, also appears in another record. I.E.: Does any record have "ABCDEFGHI" in a field, and then "ABCDEFGHI" again in that same field... but in another record. But I run into trouble when I...

Comparison of substring operation performance between .NET and Java

Taking substrings of a string is a very common string manipulation operation, but I heard that there might be considerable differences in performance/implementation between the Java and .NET platform. Specifically I heard that in Java, java.lang.String offers constant time operation for substring, but in .NET, System.String offers linear...

Regex to extract substring, returning 2 results for some reason

I need to do a lot of regex things in javascript but am having some issues with the syntax and I can't seem to find a definitive resource on this.. for some reason when I do: var tesst = "afskfsd33j" var test = tesst.match(/a(.*)j/); alert (test) it shows "afskfsd33j, fskfsd33" I'm not sure why its giving this output of original a...

What's wrong with this code??

The code is to search for a substring...the code takes in 2 inputs...the 2nd string is used to search...i.e 2nd string is smaller in length. a=input("Enter the 1st string") //Giving error here b=input("Enter the second string") com="" for x in range(0,len(a)): com="" for j in range(x,len(b)+x): com=com...

How do I use a ruby regex to get a substring?

I want to get the numbers out of strings such as: person_3 person_34 person_356 city_4 city_15 etc... It seems to me that the following should work: string[/[0-9]*/] but this always spits out an empty string. ...

Oracle SQL query count group by timestamp substring

Given a table that has a column of string "timestamps" (yyyyMMddHHmmssSSS format), I want to substring the first 8 characters, and get a count of how many rows have that substring, grouping the results. Sample data... TIMESTAMP 20100802123456123 20100803123456123 20100803123456123 20100803123456123 20100804123456123 20100805123456123 2...

Detecting an Apostrophe in a NSString?

I'm using Gamekit to send data via bluetooth between two devices. I want to get the name of the device that sent it, but if the name is "Bob's iPhone" I want to cut off the "'s iPhone". I first check for ending in "iPhone" or "iPod Touch". if ([name hasSuffix:@" iPhone"]) { name = [name substringToIndex:[name length]-7]; } else i...

How to capture complete words using substr() in PHP, limit by word?

When I use substr($string,0,100), it gives first 100 characters. Sometimes it left the last word incomplete. That looks odd. Can I do limit by word rather than char? ...

How can I replace a regex substring match in Javascript?

var str = 'asd-0.testing'; var regex = /asd-(\d)\.\w+/; str.replace(regex, 1); That replaces the entire string str with 1. I want it to replace the matched substring instead of the whole string. Is this possible in Javascript? ...

Finding a substring in a NSString object

Hi, I have an NSString object and I want to make a substring from it, by locating a word. For example, my string is: "The dog ate the cat", I want the program to locate the word "ate" and make a substring that will be "the cat". Can someone help me out or give me an example? Thanks, Sagiftwenter code here ...

Javascript substring() trickery

Hi folks I have a URL that looks like http://mysite.com/#id/Blah-blah-blah, it's used for Ajax-ey bits. I want to use substring() or substr() to get the id part. ID could be any combination of any length of letters and numbers. So far I have got: var hash = window.location.hash; alert(hash.substring(1)); // remove # Which removes th...

iOS substring question...

How can I select a string from the beginning until a specified character? For example, in the following a news headline... someString = @"Los Angeles, California - Apple announces something, stock prices change." How do I select just Los Angeles, California - into a separate string? (I want to base my selection on everything before th...

substring() in for loop causing "StringIndexOutOfBoundsException: String index out of range: -1"

public class Asterisk { public static void main(String[] args) { String output=""; int count=1, input; System.out.println("Input the size of the triangle from 1 to 50:"); input = 5; for(count=1;count <= input;count++) { output += "*"; System.out...