string-manipulation

Processing a string in php

I have a really long string in a certain pattern such as userAccountName: abc userCompany: xyz userEmail: [email protected] userAddress1: userAddress2: userAddress3: userTown: .....and so on. This pattern repeats. I need to find a way to process this string so that I have the values of userAccountName:, userCompany: etc. (i.e. preferably in a...

Extract filename and extension in bash

I want to get the filename (without extension) and the extension separately. The best solution I found so far is: NAME=`echo "$FILE" | cut -d'.' -f1` EXTENSION=`echo "$FILE" | cut -d'.' -f2` This is bad because it doesn't work if the filename contains multiple "." characters. If let's say I have a.b.js it will consider a and b.js, in...

How can I truncate a string in PHP?

How can I truncate a string after 20 words in PHP? ...

concatenating strings in C

i was wondering if there was a way to add a value to a string, not like 1 + 1 = 2 but like 1 + 1 = 11. ...

string splitting

i have a string: e.g. WORD1_WORD2_WORD3 how do i get just WORD1 from the string? i.e the text before the first underscore ...

Shorten String in PHP (full words only)

I have asked a similar question here before, but I need to know if this little tweak is possible. I want to shorten a string to 100 characters and use $small = substr($big, 0, 100); to do so. However, this just takes the first 100 characters and doesn't care whether it breaks up a word or not. Is there any way to take up to the first ...

How to make one variable = two others instead of just one

I posted this before and got a few answers that haven't worked for me so far. Therefore I'm going to post part of my code so you can see what I'm talking about. The highlighted part is what I pulled from another post and it's not working for me right now. I'm using visual studio 2008 and the program was written in Basic. I pulled mos...

String Comparison

Scenario Consider the following code snippet. string s = "S"; string s1 = "S"; string s2 = string.Empty; switch (s) { case "S": s1 = "StringComparison"; break; default: break; } switch (s[0]) { ...

Regex hackery

I have been thinking about a regular expression that can transform a list like this: 1. 10.Things.I.Hate.About.You[1999]DvDrip[Eng]-Ray 699.68 MB 2. 100.Feet.2008.DvDRip-FxM 701.14 MB 3. 11 - 14 1 286.22 MB 4. 13_going_on_30(2004)[Brizzly] 700.23 MB ... 1 523. Waz 699.93 MB 1 524. We.Own.the.Night[2007]DvDrip[Eng]-Ray 700.87 MB 1 ...

Perl script to search pattern and concat lines in a file

I have a text file (basically an error log with date, timestamp and some data) in the following pattern: mm/dd/yy 12:00:00:0001 This is line 1 This is line 2 mm/dd/yy 12:00:00:0004 This is line 3 This is line 4 This is line 5 mm/dd/yy 12:00:00:0004 This is line 6 This is line 7 I'm new at Perl and need to write a script that se...

How to do this in PowerShell? Or : what language to use for file and string manipulation?

What language should I use for file and string manipulation? This might seem objective, but really isn't I think. There's lot to say about this. For example I can see clearly that for most usages Perl would be a more obvious candidate than Java. I need to do this quite often and at this time I use C# for it, but I would like a more scr...

How could I rewrite this to remove the gotos without loss of speed or readability?

I wrote this. Yes, I know it's VB6. Yes, it is production code, and, yeah, I know it uses gotos. I am a lazy, evil beast ... So show me (and the rest of us) how it should be written Public Function SplitString(ByVal sText As Variant) As Variant Dim nHere As Long Dim cHere As String * 1 Dim aRes As Variant Dim nRes As L...

splitting string up

hi all, I have a string build up like varstring1_varstring2_id1_id2 eg: move_user_12_2 . I want to extract id1 and id2 out of the string. Since I'm a complete prototype beginner I'm having some troubles solving this. Thanks Stijn ...

ForEach String concat

Hi, A little newbie question. I have a foreach loop where I am trying to access the property of a row object and assign to a string. foreach(row in Dataset) { string finalName= row.name; } On each iteration I need to concat each row's name property to the finalName \Thanks alot, ...

How to find the second-to-last occurrence of a character within a string?

If possible, using only standard PHP functions like substr(), strrpos(), strpos(), etc. ...

C# - Show the differences when comparing strings

In my asp.net project, I have two strings (actually, they are stored in a Session object, then i do a .ToString() ) This project is part of my free Japanese language exercises on my website (Italian only for now, so i won't link/spam) For now i do an if (original == inputted.ToLower()) , but I would like to compare the strings and high...

What is the canonical way to trim a string in Ruby without creating a new string?

This is what I have now - which looks too verbose for the work it is doing. @title = tokens[Title].strip! || tokens[Title] if !tokens[Title].nil? Assume tokens is a array obtained by splitting a CSV line. now the functions like strip! chomp! et. all return nil if the string was not modified "abc".strip! # => nil " abc ".str...

How to extract string from custom characters using JavaScript?

Howdy, If I have a string between 2 square brackets that I have created on a page, how would I go about storing that value in a variable and deleting the square brackets? Example [String I want] So I'm left with var mystring = "String I want" UPDATE: It appears I can't reply to any of you. SO must be acting up. Anyway this is w...

How to improve substring detection as a suffix

I am pretty new to C# and I am pretty sure this function can be radically improved: public static Boolean SuffixExists(String strWhole, String sufx) { int iLen = sufx.Length; if (iLen > 0) { String s; s = strWhole.Substring(strWhole.Length - iLen, iLen); if (sufx != s) retu...

Need a simple Regular Expressions here

Hi guys, I'm finally parsing through wikipedias wiki text. I have the following type of text here: {{Airport-list|the Solomon Islands}} * '''AGAF''' (AFT) – [[Afutara Airport]] – [[Afutara]] * '''AGAR''' (RNA) – [[Ulawa Airport]] – [[Arona]], [[Ulawa Island]] * '''AGAT''' (ATD) – [[Uru Harbour]] – [[...