string-manipulation

Most efficient way of pulling data out of a string

I need to find out the primary key of a sqlite database. Given a string like: CREATE TABLE cia (name PRIMARY KEY, population INTEGER) or: CREATE TABLE casting(movieid INTEGER, actorid INTEGER, PRIMARY KEY (movieid, actorid)) What would the most effective way of getting an array of primary keys be using php? ...

How to remove a string?

I have an string like this: string s1 = "abc,tom,--Abc, tyu,--ghh"; This string is dynamic, and I need to remove all substrings starting with "--". Output for the example string: s1 = "abc,tom, tyu"; How can I remove these substrings? ...

C# String.Replace with a start/index (Added my (slow) implementation)

I'd like an efficient method that would work something like this EDIT: Sorry I didn't put what I'd tried before. I updated the example now. // Method signature, Only replaces first instance or how many are specified in max public int MyReplace(ref string source,string org, string replace, int start, int max) { int ret = 0; in...

Trim characters in Java

How can I trim characters in Java? e.g. String j = “\joe\jill\”.Trim(new char[] {“\”}); j should be "joe\jill" String j = “jack\joe\jill\”.Trim("jack"); j should be "\joe\jill\" etc ...

MySQL: Replace substring if string ends in jpg, gif or png

Hi gang, I'm doing a favor for a friend, getting him off of Blogger and onto a hosted WordPress blog. The big problem is, with over 1,800 posts, there are a lot of image links to deal with. WordPress has no mechanism to import these automatically, so I'm doing it manually. I've used wget to download every single image that has ever be...

Regular expression to match text between <a ..> and </a>

Could anyone be able to give a regular expressiont to match the link text between <a> and </a> tags in a HTML snippet. Sample data: <a href="link.html">Link Title</a> - 15 comments <br/> <a href="otherlink.html">Some other Title</a> - 6 comments Requirement: I need to extract only the link texts (i.e. the one between <a> and </a> - Lin...

remove "<" and ">" tags from an array in php

i have an array like this Array ( [0] => "<[email protected]>" [1] => "<[email protected]>" [2]=> "<[email protected]>" ) now i want to remove "<" and ">" from above array so that it look like Array ( [0] => [email protected] [1] => [email protected] [2] => [email protected] ) how to do this in php? please help me out I'm ...

Extracting Values from a String

Hello, I am trying to extract values from a string, I have tried to get re.match working but have not had any luck. The string is: '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' I have tried: map(int,re.search("Value\s*=\s*").group(1)) and also: '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = ...

How do I concatenate a vector of strings/character in R?

If I have a vector of type character in R, how can I concatenate the values into string? Here's how I would do it with paste(): sdata = c('a', 'b', 'c') paste(sdata[1], sdata[2], sdata[3], sep='') yielding "abc". But of course, that only works if I know the length of sdata ahead of time. ...

Visual Basic Loop and Display one line at a time

I'm using visual studios 2008, VB9 and I am trying to write an app that basically performs calculations on a set of data input by a user. During the calculations, I want to display the data at each step, and have it retained in the display area on the GUI (not overwritten by the next data being displayed). For example: UserInput = 1 D...

How to find all substrings of a string

I need to convert strings of the form "a b c" into arrays of the form Array ( [0] => a [1] => a b [2] => a b c [3] => b [4] => b c [5] => c ) Does PHP provide a native function for converting strings into all substrings? If not, what's the path of least resistance for getting all substrings? Is there a str...

Best way to convert unsigned char * to int ?

Hello I have an unsigned char * that looks (after printf) like this (it's a SHA-1 hash): n\374\363\327=\3103\231\361P'o]Db\251\360\316\203 I need to convert this unsigned char * to an unsigned int, what do you think it would be the best way to do it ? I have some ideas, but I'm not a C expert so wanted to see someone else ideas before...

URL Friendly Username in PHP?

On my PHP site, currently users login with an email address and a password. I would like to add a username as well, this username they g\set will be unique and they cannot change it. I am wondering how I can make this name have no spaces in it and work in a URL so I can use there username to link to there profiles and other stuff. If ...

Finding links in raw text string

Hi all, I'm in a situation where I have a string of raw text where I want to find all links (starting with Http://) and place <a href="thelink"> before the start of the link and then a </a> after the link. The problem is, that I don't know when the link ends. I.e.: (http://www.mylink.com) In the above example, I am able to find th...

Take substring of a string in c.

I want to take a substring of the string buffer by doing something like the below. I don't know if it's possible (I've been coding in C for all of about 6 hrs now, but feel free to be as technical as you like, I think I can handle it (though I may be wrong)) Edit: I want to take a substring of buffer from the beginning of buffer to the...

replace a particular value in a string of key - values

I have a large string which is a collection of key (space)+ value, i.e key followed by one or more space and then value. Now i need to change the value of a particular key using sed, awk, grep etc. in unix environment. eg. of string: -Key1 Value1 -Key2 Value2 -Key3 Value3 I need a new string that is same as above only Va...

PHP function not returning string

Hi there I have constructed a function that takes a filename, and increments a counter in the filename and returns it, however, everything is correct, except the return does not return the filename. Any help, please? My code: $filename = join("", array_reverse($date)); $filename .= ".xml"; $dir = "../gigs"; $file = $dir."/".$filename...

Looping over datasets in Python

I'm trying to write a Python script that will perform the same action on multiple databases. There are too many for me to input them by hand, so I'd like to write a script that will loop over them. Right now, I've gotten as far as the following before getting stuck: countylist = ['01001','01002','01003','01004'] for item in countylist: ...

How in C# to reformat string, representing a decimal, to have space group separator?

I have found on SO some posts, regarding formatting strings, representing numbers, to have digit group separators, during converting decimals (or other number data types) to string: http://stackoverflow.com/questions/2100472/how-to-format-1700-to-1700-and-1000000-to-1000000-in-c http://stackoverflow.com/questions/1142994/c-formating-pr...

String processing during table creation and inserting from another table

I have a table that contains file paths, like so: -------------------- |Files | -------------------- |path nvarchar(500)| -------------------- I want to split it into two tables, one containing unique directories and one containing filenames: --------------------------- |Files | ------------------------...