string-manipulation

How to extract text before a period from a string in C#?

Say I have a string whose text is something like, "mohdibrahim.tasal". I want to extract "mohdibrahim" from this string. I've tried this code: string updateUser1 = user1.Trim(); Is this the correct approach, or is there another technique I should be using? ...

C#: How to Delete the matching substring between 2 strings?

If I have two strings .. say string1="Hello Dear c'Lint" and string2="Dear" .. I want to Compare the strings first and delete the matching substring .. the result of the above string pairs is: "Hello  c'Lint" (i.e, two spaces between "Hello" and "c'Lint") for simplicity, we'll assume that string2 will be the sub-set o...

Most reliable split character

Update If you were forced to use a single char on a split method, which char would be the most reliable? Definition of reliable: a split character that is not part of the individual sub strings being split. ...

Use Python to insert xml markup around the difference of two strings

I have an oldstring: 'foobarba <span class="foo">z</span>' and a newstring: 'foodbar ba<span class="foo">z</span>' a string is given for a classname, it could be "foo" again, let's say "bar". Given newstring, oldstring and bar, I want to end up with: 'foo<span class="bar">d</span> ba<span class="foo">z</span>' I want to diff th...

Is there a tool to automatically replace a bunch of GUIDs with dynamically-generated ones?

I'm not a developer. I need to hack an XML file to duplicate hundreds of resources that are each assigned a GUID. Is there a way to parse the entire file, replacing each GUID found in a tag with a dynamically generated one? Basically - every UniqueID tag (but not the ContentUniqueID tags) needs a new GUID. <root xmlns:xsi='http://ww...

std::stringstream to read int and strings, from a string.

Hi everyone, I am programming in C++ and I'm not sure how to achieve the following: I am copying a file stream to memory (because I was asked to, I'd prefer reading from stream), and and then trying to access its values to store them into strings and int variables. This is to create an interpreter. The code I will try to interpret is ...

SQL Substring using two charindexes problem

I have the following query: DECLARE @str VARCHAR(500) SET @str = 'Barcode: 22037 CaseSize: 1 Qty: 3' SELECT RTRIM(LTRIM( SUBSTRING(@str, CharIndex('CaseSize: ', @str) + 10, CHARINDEX('Qty:', @str)) )) The following results in: '1 Qty: 3' I would like to be able to only select the Case Size number, which is one in t...

C# : How to convert string to DateTime, where the string can have any of the standard datetime format ...

I had posted a question on DateTime to String conversion, I got many satisfying answers for that .. so I thank StackOverflow very much .. Here is one more problem of String manupulation, I am stuck with .. I have to convert a string (from some external source) using C# code .. the string can have these expected format of DateTime .. 02...

String Manipulation in PHP

How to take off 1 in "{1}" and use it? ...

Capitalize First Char of Each Word in a String Java

Is there a function built into Java that capitalizes the first character of each word in a String, and does not affect the others? Examples: jon skeet -> Jon Skeet miles o'Brien -> Miles O'Brien (B remains capital, this rules out Title Case) old mcdonald -> Old Mcdonald* *(Old McDonald would be find too, but I don't expect it to be ...

convert string list to list in python

I was wondering what the simplest way to convert a string list like x =u'[ "A","B","C" , " D"]' -in case user puts spaces in between the commas , and spaces inside of the quotes . I need to handle that as well to x = ["A","B","C","D"] in python. I know I can strip spaces with strip and split using the split o...

How can I replace every instance of a pattern in ruby?

string.sub looks like it only replaces the first instance. Is there an option for that or another method that can replace all patterns? Can you do it inside a regex like perl? (I think something like r/blah/blah/) ... and +1 to anyone who can tell me WHY ON EARTH does string.sub replace just the FIRST match? ...

asp.net flip string (swap words) between character

Hi all, My scenario is i have a multiline textbox with multiple values e.g. below: firstvalue = secondvalue anothervalue = thisvalue i am looking for a quick and easy scenario to flip the value e.g. below: secondvalue = firstvalue thisvalue = anothervalue Can you help ? Thanks ...

PHP Sting Function Zip+4 to Zip

I'm looking to convert US Format Zip Code 00000-1234 to 00000. But the zip may also be Canadian, UK or the World for that matter. So I guess a sanity check would be that you have 5 digits all 0-9 followed by a dash followed by 4 digits 0-9. If that fails leave the string alone if it passes trim off everything to the Right of the 5th d...

Formatting strings in java

I am reading the serial buffer with readLine() method. The string returned by readLine() is in the format "str1 : str2". In a while loop when I use readLine() number of times for a response of serial port command I get weird output like this : String1 : string1 SString11 : String2 StringString2 : String23 String4 : String5 But I need...

Most efficient method to parse small, specific arguments

I have a command line application that needs to support arguments of the following brand: all: return everything search: return the first match to search all*search: return everything matching search X*search: return the first X matches to search search#Y: return the Yth match to search Where search can be either a single keywor...

String operation in ruby for credit card number

Working on a rails project where there's an order confirmation string with a credit card number with all but the last four digits starred out. What's the proper way to do a string substitution? What's the operation to get this credit_card_number = "1111111111111111" to this? credit_card_number = "************1111" Thanks, Kenji ...

Replace a string with a user control

How can I replace a string with UserControl? if string = [$control1$] replace with control1.ascx ...

get value in jquery

i have one function which return value in this format li#2.ui-widget-content li#6.ui-widget-content li#12.ui-widget-content li#1.ui-widget-content each time i run function i get random value in the above format. i want to get value after li# in jquery Thanks ...

read characters and words in HTML text using javascript

consider that i am getting a HTML format string and want to read the number of words & characters, Consider, i am getting, var HTML = '<p>BODY&nbsp;Article By Archie(Used By Story Tool)</p>'; now i want to get number of words and characters above html will look like: BODY Article By Archie(Used By Story Tool) IMPORTANT i want...