string-manipulation

How do I trim the number of words in Python?

For example... s = 'The fox jumped over a big brown log.' k = FUNCTION(s,4) k should be... "The fox jumped over" I can write my own function that splits on whitespace, cuts the list and then joins the list. But that is too much work. Anyone else knows a simpler way? ...

C# superfast "mailmerge" type replace

I hoping for some pointers on the quickest way to do a replace when the document that needs bits replacing is constant (a sort of mailmerge scenario). Of course there are lots of ways of doing replaces using string.replace and regexp but it looks like they need to parse the input document each time looking for the match. That's the bit ...

An efficient solution to a String.Replace problem?

Say I have an array of Strings declared like this: String[] strings = new String[ 1024 ]; And given an array of key value pairs declared like this: KeyValuePair<String, String>[] pairs = new KeyValuePair<String, String>[ 50 ]; What are the possible workarounds for a solution that would do this: for ( int i = 0; i < 1024; ++i ) { ...

Algorithms for splitting personal names in parts

I'm looking for references on separating a name: "John A. Doe" in parts, first=John, middle=A., last=Doe. In Mexico we have paternal, maternal, first and second given names, and can be written in different permutations, so the problem is quite complex. As it depends on data, we are working with matching software that calculates a score ...

python line.split semantic error fromtext file

this section of code is supposed to make a list containing the values of the second column in the text file, but it takes the second letter. anyone know what my problem is? TEXTFILE opi 60 kid 60 pou 60 ret 60 kai 60 bob 100 for line in lst: line.split(' ') fire.append(int(line[1])) ...

PHP and file manipulation

I was wondering if it is possible to open an xml file as a plain text file so I can read in each line and manipulate the text? ...

Is there a reverse fn() for strstr

All, I am trying to find a similar function to 'strstr' that searches a substring starting from the end towards the beginning of the string. Thanks ...

vb.net: can you split a string by a string

for example, can i do this: split = temp_string.Split("<beginning of record>") those of you recommended: split = Regex.Split(temp_string, "< beginning of record >") its not working. its just returning the first char "<" and those of you that recommended: Dim myDelims As String() = New String(){"< beginning of record >"} split = t...

PHP Split a string with start and stop value

I have fooled around with regex but can't seem to get it to work. I have a file called includes/header.php I am converting the file into one big string so that I can pull out a certain portion of the code to paste in the html of my document. $str = file_get_contents('includes/header.php'); From here I am trying to get return only th...

Smalltalk - Compare two strings for equality

I am trying to compare two strings in Smalltalk, but I seem to be doing something wrong. I keep getting this error: Unhandled Exception: Non-boolean receiver. Proceed for truth. stringOne := 'hello'. stringTwo := 'hello'. myNumber := 10. [stringOne = stringTwo ] ifTrue:[ myNumber := 20]. Any idea what I'm doing wrong? ...

Smalltalk - Inserting a TAB character (Visual Works)

I'm having some trouble inserting a tab between two strings. stringOne := 'Name'. stringTwo := 'Address'. I've tried: info := stringOne, String tab, stringTwo. or info := stringOne, Character tab asString, stringTwo. But none of those two messages are understood. I'm using Visual Works. ...

What's the most elegant way to concatenate a list of values with delimiter in Java?

I have never found a neat(er) way of doing the following. Say I have a list/array of strings. abc def ghi jkl and I want to concatenate them into a single string delimited by a comma as follows: abc,def,ghi,jkl In Java, if I write something like this (pardon the syntax) String[] list = new String[] {"abc","def","ghi","jkl"}; Str...

Java: Is there any simpler way to parse array elements from string?

Hi, In the application there is a string in the following format: String elements = "[11, john,][23, Adam,][88, Angie,]..." (... means there are more elements in the string) From the given string I have to create an ArrayList for name IDs (11, 23, 88, ...) and ArrayList for names (john, Adam, Angie, ...) I created two methods: priv...

Is String.replace any faster than String.split ... String.join in ActionScript 3?

Is it any faster to use myString.replace(/foo/g,"bar") rather than myString.split("foo").join("bar") for long strings in ActionScript 3? Or are they just two comparable methods of achieving the same result? ...

Path.Combine with spaces in passed parameter?

string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath; string exeDir = Path.GetDirectoryName(exeFile); string fileName = Path.Combine(exeDir, @"..\..\xml\SalesOrderXMLData.csv.xml"); Hello, The above code works if the project is in, for example, C:\Code\ but not if its in C:\Documents and S...

SQL Extract substring

I'm having an issue extracting a substring in SQL query results. Here's the situation: I have a column that contains strings in the following format "ax123456uhba", "ax54232hrg", "ax274895rt", "ax938477ed1", "ax73662633wnn2" I need to extract the numerical string that is preceded and followed by letters. However, occasionally there is...

PHP Concatenation becomes NULL

When I run this code, About half-way through the concatenation loop, $xml becomes null and remains null throughout the rest of the concatenation loop. Has anyone else ran into this? Or see why this is happening? $xml = ''; foreach($this->currentColumns['unknown'] as $column => $value) { $xml .= "<columnName>"; $xml .= $column; ...

In C#, Checking string length greater than zero produces error?

This question sounds outrageous, but VS is giving me an error when I check that a string length is greater than zero: options[j]["pdprice"].ToString().Length > 0 Saying: CS0019: Operator '>' cannot be applied to operands of type 'string' and 'int' Can someone please explain why I cannot check that an integer length property is g...

C#: Snippet extraction based on search term on a single document

I have the text from a PDF document available to me, and I want to display snippets from the text everywhere the user-entered search phrase appears. Say the search term is"iphone", I want to display 200 characters around each iphone word instance in the document. Ideally, the snippet should also start from the beginning of a sentence. ...

how to remove spaces in and of text field - need it in and sql query for oracle

i have field X that contain text with spaces in the end of the text how i can remove them ? i need it in any sql query for oracle 10g ...