string-manipulation

Java String.replaceAll regex

What is the regex to strip the MY-CORP\ part of na inputed string like MY-CORP\My.Name with the java String.replaceAll method so I can get only the My.Name part? I tried public static String stripDomain(String userWithDomain) { return userWithDomain.replaceAll("^.*\\", ""); } but i got Unexpected internal error near index 4 ^.* ...

PHP startsWith() and endsWith() functions

I need two functions that would take a string and return if it starts with the specified character/string or ends with it. For example: $str='|apples}'; echo startsWith($str,'|'); //Returns true echo endsWith($str,'}'); //Returns true ...

PHP ltrim() and rtrim() functions

I need 2 functions that take a string and the number of chars to trim from the right and left side and return it. E.g: $str = "[test]"; $str = ltrim($str,1); //becomes test] $str = rtrim($str,1); //becomes test Thoughts? ...

Best approach to holding large editable documents in memory

I need to hold a representation of a document in memory, and am looking for the most efficient way to do this. Assumptions The documents can be pretty large, up to 100MB. More often than not the document will remain unchanged - (i.e. I don't want to do unnecessary up front processing). Changes will typically be quite close to each oth...

Stripping everything but alphanumeric chars from a string in PHP

I'd like a regexp or other string which can replace everything except alphanumeric chars (a-z and 0-9) from a string. All things such as ,@#$(@*810 should be stripped. Any ideas? Edit: I now need this to strip everything but allow dots, so everything but a-z, 1-9, .. Ideas? ...

Is there a cleaner way to write this block of code that parses a delimited string into an object?

Is there a more elegant way to structure the following code, which takes a comma delimited string containing certain values in specific positions and assigns the values to the properties of an object? // split comma delimited items into a string array Dim items As String() = myList.Split(CChar(",")) // Assign my...

Use C# regex to convert casing in a string

Hi, how can I convert this string: bKk_035A_paint-House_V003 to BKK_035a_paint-House_v003 with a regular expression (e.g. Regex.Replace)? This regex matches the string: ^(?<Group1>[a-z][a-z0-9]{1,2})_(?<Group2>\d{3}[a-z]{0,2})_(?<Group3>[a-z-]+)_(?<Group4>v\d{3,5})$ Group1 = uppercase Group2 = lowercase Group3 = unchanged ...

How to get the token type from a CFStringTokenizer in Cocoa?

The CFStringTokenizer documentation has two conflicting statements in CFStringTokenizerAdvanceToNextToken(): CFStringTokenizerAdvanceToNextToken ... Return Value The type of the token if the tokenizer succeeded in finding a token and setting it as current token. Returns kCFStringTokenizerTokenNone if the tokenizer fail...

Algorithm for analyzing text of words

I want an algorithm which would create all possible phrases in a block of text. For example, in the text: "My username is click upvote. I have 4k rep on stackoverflow" It would create the following combinations: "My username" "My Username is" "username is click" "is click" "is click upvote" "click upvote" "i have" "i have 4k" "have 4...

string.Replace not behaving as expected

Can someone explain why I get different results from these two statements? I thought that reassigning the value to the same variable would result in the value I get in the above example. What am I missing here? _body.Replace("##" + _variableName + "##", templateVariables[_variableName]) Hello pitty ##LastName##, _body = _body.Rep...

What's an efficient way to concatenate all strings in an array, separating with a space?

Let's say I have an array of strings: string[] myStrings = new string[] { "First", "Second", "Third" }; I want to concatenate them so the output is: First Second Third I know I can concatenate them like this, but there'll be no space in between: string output = String.Concat(myStrings.ToArray()); I can obviously do this in a loo...

Perform JavaScript .replace in JQuery

How would I perform the following in JQuery? var elmOperator = document.getElementById(elm.id.replace('Include', 'Operator')); The ID that is being manipulated would look something like Criteria[0].Include. I am trying to create a variable for a related ID which is Criteria[0].Operator. Thanks in advance! ...

What is the best way to format a string in Scala?

I was wondering what the best way to format a string would be in Scala. I'm reimplementing the toString method for a class, and it's a rather long and complex string. I thought about using String.format but it seems to have problems with Scala. Is there a native Scala function for doing this? ...

Regular expression to find and replace a string in a xml

I'm looking for one regular expression that could match a string for three specific cases in a xml file: : Double-quotes surrounding a string. : A string surrounded by the characters greater than and Less Than. : A string surrounded by the characters ; and &. Example: "MyString" - Valid match >MyString< - Valid match ;MyString - I...

Is there any better way to do filefilter for many ext?

File files[] = rootDir.listFiles(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) return true; String name = file.getName().toLowerCase(); if (name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith(".z") || name.endsWith(".gz") || name.endsWith(".tar") || n...

Problem Checking the End of a String

This seems to be a very odd problem that I cannot figure out for the life of me. I have a path (string) that looks like this: D:\development\php\bchat\chat\index.php I need to check if the file in question is a PHP file. I figure the most logical way is to take a substring starting from the . to the end of the string and see if it ...

Should I use \r or \n for explode()ing the contents of a file in PHP?

I'm creating a function which can accept a string which is either retrieved through file_get_contents() on a local text file, or something fetched from a url such as http://site.com/338383.txt. The file will be a tab seperated file, with each item in the file being on its own line. Is it better to use \n or \r to explode() the string an...

Removing carriage return and new-line from the end of a string in c#

Guys how do I remove the carriage return character(\r) and the new line character(\n) from the end of a string? ...

How does one encode and decode a string with Python for use in a URL?

Hi, I have a string like this: String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] I would like to encrypt String A to be used in a clean URL. something like this: String B: [ cYdfkeYss4543423sdfHsaaZ ] Is there a encode API in python, given String A, it returns String B? Is there a decode API in python, given String B,...

How can I use credit card numbers containing spaces?

Some fancy websites show an error dialog when it is detected that an untrained shopper has entered a credit/debit card number as it is printed on their card with spaces. Is it possible in some way to write a Java web app that handles these numbers with spaces as if they were correct? ...