string-manipulation

Extracting date from String

I'd like to extract a date from any string entered. But not specific to a date format (otherwise I'd use some sort of regex) e.g "Pictures taken in Africa 3 weeks ago" The php parser would extrace "3 weeks ago" and I can happily convert this. Does anyone know of the best method to perform this or of any library that can do it for me...

Catching some exceptions but ignoring others - why doesn't this work?

I have something similar to this. void func() { try { //socket disconnects in middle of ..parsing packet.. } catch(Exception ex) { if(!ex.getMessage().toString().equals("timeout") || !ex.getMessage().toString().equals("Connection reset")) { debug("Exception (run): " + ex.getMessage()); ex.printStackTrace(); } } ...

PHP remove accents

What is the most efficient way to remove accents from a string eg. "ÈâuÑ" becomes "Eaun" Is there a simple, built in way that I'm missing or a regular expression? ...

Grab variable from php URL string

What's the easiest way to grab a 6-character id from a string? The id will always be after www.twitpic.com/ and will always be 6 characters. e.g., $string = 'The url is http://www.twitpic.com/f1462i. Enjoy.'; $id = 'f1462i'; Thanks. ...

Remove accents without using iconv

What is the best way to remove accents eg. ÈâuÑ" becomes "Eaun" Without using iconv ...

How can i get the numerical value (convert it to int) from a string?

I only see strings with only numbers. this is my string. SMUL 9 A B How can I get the number 9 as int type. Other possible string may be: SMUL 13 A B SMUL 43 100 21 ...

How do I split a string and rejoin it without creating an intermediate list in Python?

Say I have something like the following: dest = "\n".join( [line for line in src.split("\n") if line[:1]!="#"] ) (i.e. strip any lines starting with # from the multi-line string src) src is very large, so I'm assuming .split() will create a large intermediate list. I can change the list comprehension to a generator expression, but i...

How can I split strings into different types (int for numerical values and char for letters)?

For example, I have this string: SMUL 9 A B? How can I get 9 (int type) A (char) and B (char). Possible string may be SMUL 12 A C, so it means their positions in the string is not constant. Further explanation: this is a string inputted by a user for my matrix calculator program. Inputting SMUL "scalar" "matrix-1" "matrix-2" means that ...

clear a given commandline string to match filepath

Hello, my application processes strings with commandlines. I need to get the string to the given executable that is called for example: "C:\windows\system32\notepad.exe bla.txt" => C:\windows\system32\notepad.exe "C:\windows\system32\ipconfig /all" => C:\windows\system32\ipconfig "D:\this is my path\thisismyexe.exe -l this -p are -m my ...

How to read formatted data in C++?

I have a formatted data like the following: Words 5 AnotherWord 4 SomeWord 6 It's in a text file and I'm using ifstream to read it, but how do I separate the number and the word? The word will only consist of alphabets and there will be certain spaces or tabs between the word and the number, not sure of how many. ...

How to split a string on * and - in PHP?

Inorder to split the string i have used the following code. $string = "-sev*yes-sev1*no-sev2*yes"; split('[-*]', $string). As split is deprecated, can you please suggest an alternative to split the string into an array. I have tried with explode, but it is not serving my purpose. The output should look like, Array ( [0] => sev ...

C#: string[] to delimited string. Is there a one-liner?

What I'd prefer is something like: string[] strArray = {"Hi", "how", "are", "you"}; string strNew = strArray.Delimit(chDelimiter); However, there is no such function. I've looked over MSDN and nothing looked to me as a function that would perform the same action. I looked at StringBuilder, and again, nothing stood out to me. Does an...

C++ append to string and write to file

Why does the following code not work #include <iostream> #include <fstream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; int main(){ string data; int i=0; while(i <= 5){ i++; data += i; data += "\n"; } ofstream myfile; myfile.open ("data.txt"); myfile <<...

string starting by ^Bo

Does anybody know what ^Bo means at the beginning of a encoded string? The rest of the string is valid ASCII. Example: "^BoHello" should be interpreted as "Hello" Note: '^B' is the control character 0x02 ...

String replacement

For example i have this string: $test_str = "num Test \n num Hello \n num World"; And i need to replace these num-s to increasing numbers. like that "1 Test \n 2 Hello \n 3 World" How could i do this? ...

BestPractice - Transform first character of a string into lower case

I'd like to have a method that transforms the first character of a string into lower case. My approaches: 1. public static string ReplaceFirstCharacterToLowerVariant(string name) { return String.Format("{0}{1}", name.First().ToString().ToLowerInvariant(), name.Substring(1)); } 2. public static IEnumerable<char> FirstLetterToLow...

How to remove part of a string?

Let’s say I have test_23 and I want to remove test_. How do I do that? The prefix before _ can change. ...

preg_replace ".php"?

Hi. How do I preg_replace .php from end of string? for ($x = 0; $x < count($sidebar_links); $x++) { $sidebar[$x] = $x; } $sidebar_links: array(3) { [0]=> string(9) "index.php" [1]=> string(9) "site2.php" [2]=> string(7) "site3.php" } ...

Truncating Strings in Java by Bytes

Hey all. I create the following for truncating a string in java to a new string with a given number of bytes. String truncatedValue = ""; String currentValue = string; int pivotIndex = (int) Math.round(((double) string.length())/2); while(!truncatedValue.equals(currentValue)){ currentValue ...

PHP extract text from string - trim?

I have the following XML: <id>tag:search.twitter.com,2005:22204349686</id> How can i write everything after the second colon to a variable? E.g. 22204349686 ...