substring

Finding a loose match for a string in arraylist

Hi folks, I have a huge array list which contains 1000 entries out of which one of the entry is "world". And, I have a word "big world". I want to get the word "big world" matched with "world" in the arraylist. What is the most cost effective way of doing it? I cannot use .contains method of array list, and If I traverse all the 1000 e...

Postgresql count substring with a "where" clause

I am trying to count a substring, while matching different values from another column. The following statement gives me a syntax error on the where clause. Is the following even possible, and what is the correct syntax? select address, datacenter, ifdesc, count(substring(ifdesc, 'Ethernet0/*') where ifadminstatus ...

How can I truncate data to fit into a field using SQL*Loader? (ORA-12899)

Using Oracle SQL*Loader, I am trying to load a column that was a variable length string (lob) in another database into a varchar2(4000) column in Oracle. We have strings much longer than 4000 characters, but everyone has agreed that these strings can and should be truncated in the migration (we've looked at the data that goes beyond 400...

SubstringToIndex memory leak

I'm using this function to extract a substring, it works but there are two leaks: -(NSString*)EstraiP:(NSString*)str ini:(NSString*)ini fin:(NSString*)fin occ:(int)occ{ NSRange rstr1; for(int i=0; i < occ; i++){ rstr1=[str rangeOfString:fin]; str=[str substringFromIndex:rstr1.location+rstr1.length]; }...

How do i go about searching in Ruby on Rails?

I would like to implement a simple search. Let's say the user enters 'york', then I would like to find all records that has a matching substring like 'new york' or 'yorkshire'. So far I have figured out I will have to use the find method, but I can't figure out how to match for substrings. ...

What is the fastest substring search algorithm?

OK, so I don't sound like an idiot I'm going to state the problem/requirements more explicitly: Needle (pattern) and haystack (text to search) are both C-style null-terminated strings. No length information is provided; if needed, it must be computed. Function should return a pointer to the first match, or NULL if no match is found. Fa...

freeing substring in c - loop

I'm trying to get a sub-string for each member of the struct 'structs' and then assign that sub-string to a new member of the temp_struct. The problem I'm having is how to free the sub-string on each iteration, for some reason the code runs, however valgrind throws an Invalid read of size 1, which I assume I'm reading off the block of m...

Index of substring in SQLite3?

What's the most straightforward way of finidng the index of a substring in a varchar column? charindex doesn't exist in the stock version of SQLite3 -- which is still a little surprising to me. Specifically, I have a column with values like 010000, 011000, 010110, etc. I want to find the index of the first occurence of 11. For the ex...

freeing substring without doing double free in c

Yesterday I asked a similar question regarding how to free allocated memory for a sub-string. Now I have one more question regarding the same problem (involving a set of conditions), how could I free the following sub-string without doing double free? #include <stdio.h> #include <stdlib.h> #include <string.h> struct st_ex { char pr...

Ruby has no "String#substrings_between(start, end)", what should I use?

I have a very complex string, such as: <p>aaa <font style="color:red">ABCD@@@EFG^&*))*T*^[][][]</p> <p>bbb <font style="color:red">ABCD@@@EFG^&*))*T*^[][][]</p> <p>ccc <font style="color:red">ABCD@@@EFG^&*))*T*^[][][]</p> .... Now I want to get the aaa,bbb,ccc parts. I don't want to use regular expression here, because it's too compli...

Fastest way to remove first char in a string

Say we have the following string string data= "/temp string"; If we want to remove the first character / we can do by alot of ways such as : data.Remove(0,1); data.TrimStart('/'); data.Substring(1); But .. really I don't know which one have the best algorithm and doing that faster .. Is there a one that is the best or all are the...

Range of substring in string.

Hi, Is the a way to get the NSRange of an NSString in an NSString? ...

substring(startIndex, endIndex) - why index out of range is not thrown?

I came across some substring() method mystery and not sure why it is not throwing out of index error. The string "abcde" has index start from 0 to 4 but substring() method takes startIndex and endIndex as arguments which I believe zero base based on the fact that I can call foo.substring(0) and get "abcde" Then why substring(5) works???...

SQL Server - Select integer that falls between brackets ( )

HI, how can i select the Integer that falls between a pair of ( ) begining from the right of a cell? Reason being, there might be another pair of brackets containing characters and what if some records are w/o close brackets for some reason.. e.g. Period | ProgrammeName | Jan | ABC (Children) (30) | Feb | H...

perl regexp replace string with a substring of the regular expression

Hello I have a question concerning perl. Assume I have the following line in my file: DoMatchLong ( "ThisIsMyVariable", lThisIsMyVariable); I want to replace "ThisIsMyVariable" by cp_const_ThisIsMyVariable So my aim is: DoMatchLong ( cp_const_ThisIsMyVariable, lThisIsMyVariable); $count = s/(?<=")\w+(?=")/const_cmd_cp_$&/gx; lea...

iphone string initial char before space

Hi all! I have a question... I wish take from a string that contains a name and surname, the initial of the first and the surname complete.... example: NSString* myName = @"Mel Gibson"; //I Wish have "M Gibson"; NSString* myName2 = @"Leonardo Di Caprio"; //I wish have "L Di Caprio"; Thanks ...

How to find rows in SQL that start with the same string (similar rows)?

I have a table with primary keys that look like this: FIRSTKEY~ABC SECONDKEY~DEF FIRSTKEY~DEF I want to write a SELECT statement that strips off the segment following the tilde and returns all rows that are duplicates after the post-tilde segment is gone. That is, SELECT ... Gives me: FIRSTKEY~ABC FIRSTKEY~DEF As "duplicates". ...

Cut an UTF8 text in PHP

Hi, I get UTF8 text from a database, and I want to show only the first $len characters (finishing in a word). I've tried several options but the function still doesn't work because of special characters (á, é, í, ó, etc). Thanks for the help! function text_limit($text, $len, $end='...') { mb_internal_encoding('UTF-8'); if( (mb_...

Databinder.Eval and Substring

Im using a repeater control and a databinder to display data from the database to my website. example: DataBinder.Eval(Container, "DataItem.title") Sometimes the text is too long Normally I use substring to display the preferred string in length. But How do I do this with the databinder And if the text is too long (> 20 characters) I w...

Find string between two substrings

How do I find a string between two substrings ('123STRINGabc' -> 'STRING')? My current method is like this: >>> start = 'asdf=5;' >>> end = '123jasd' >>> s = 'asdf=5;iwantthis123jasd' >>> print((s.split(start))[1].split(end)[0]) iwantthis However, this seems very inefficient and un-pythonic. What is a better way to do something like ...