string

Can I initialize a const string from a const char in C#?

I am trying to do the following in a way or another: const char EscapeChar = '\\'; const string EscapeString = EscapeChar.ToString(); // or ("" + EscapeChar) This does't compile. Is there another way to make it work? ...

Simple way to extract part of a file path?

I'm not very good at C, and I always get stuck on simple string manipulation tasks (that's why I love Perl!). I have a string that contains a file path like "/Volumes/Media/Music/Arcade Fire/Black Mirror.aac". I need to extract the drive name ("Media" or preferably "/Volumes/Media") from that path. Any help would be greatly appreciate...

How to avoid a common bug in a large codebase?

Is there a way to undefine the += on strings and wstrings for chars and wchar_t? Basically I want to avoid bugs like the following: int age = 27; std::wstring str = std::wstring(L"User's age is: "); str += age; std::string str2 = std::string("User's age is: "); str2 += age; The above code will add the ascii character 27 to the stri...

Mix two strings into one longer string PHP

I have two strings and I would like to mix the characters from each string into one bigger string, how can I do this in PHP? I can swap chars over but I want something more complicated since it could be guessed. And please don't say md5() is enough and irreversible. :) $string1 = '9cb5jplgvsiedji9mi9o6a8qq1';//session_id() $string2 = '...

Howto bind TextBox control to a StringBuilder instance?

I would like several textboxes to react to changes of an underlying string. So if I were to change the content of the string, all those textboxes would change their content too. Now, I can't use the String type for that as it is immutable. So I went with StringBuilder. But the Text property of a TextBox object only takes String. Is the...

Generate string from Grouping Linq Query

Hi, Given the following code: var people = new List<person>(){ new person { Name = "John", FamilyName = "Pendray" }, new person { FamilyName = "Emery", Name = "Jake"}, new person { FamilyName = "Pendray", Name = "Richard" } }; var q = from p in people orderby p.Name group p by...

What is the best way to find specific tokens in a string (in Java)?

I have a string with markup in it which I need to find using Java. eg. string = abc<B>def</B>ghi<B>j</B>kl desired output.. segment [n] = start, end segment [1] = 4, 6 segment [2] = 10, 10 ...

How to generate 2-characters long words effectively?

Hello, I've been playing with idea to make a script to generate 2-characters words from a given set of characters in my language. However, as I am not into re-inventing the wheel, do you know about such a script publicly available for C#? ...

VB.NET- Peformance when testing an empty string

In VB6, I was told that when testing for an empty string, it would be much faster to check this by verifying the length of the string by using : If Len("ABC") = 0 then 'fast or If LenB("ABC") = 0 then 'even faster instead of: If "ABC" = "" then 'slower Do you know by any chance if this is true also in VB.NET? Thank you. ...

Coalesce vs empty string concatenation

My coworker is new to C# and didn't know about the coalesce operator. So, I saw him write a line of code like this: string foo = "" + str; The idea being that if str is null, this expression would return an empty string. Of course, that could be rewritten as this: string foo = str ?? ""; And I feel that would be more readable. B...

String Comparison : individual comparison Vs appended string comparison

I have six string variables say str11, str12, str13, str21, str21 and str23. I need to compare combination of these variables. The combinations I have to check is str11 -- str12 -- str13 as one group and str21 -- str22 -- str23 as other group. I have to compare these two groups. Now I'm in confusion which method should I use for compa...

Can an App.Config be loaded from a string or memory stream?

I know that I can load an app.config file from a different location using the following line of code: AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", ConfigFile); where ConfigFile is a full path location. What I'd like to do though is be able to load a file that has been encrypted for the app.config. Ideally, I'd like to be able to...

C# String comparisons: Difference between CurrentCultureIgnoreCase and InvariantCultureIgnoreCase

When doing a string comparison in C#, what is the difference between doing a string test = "testvalue"; test.Equals("TESTVALUE", StringComparison.CurrentCultureIgnoreCase); and string test = "testvalue"; test.Equals("TESTVALUE", StringComparison.InvariantCultureIgnoreCase); ... and is it important to include that extra parameter, ...

K&R Exercise 2-4

I'm learning how to write programs in C using the k&r book (The C Programming Language) and I have a problem with one of the exercises. It's asking me to detect and remove a character in string s1, which matches any characters in the string s2. So, say s1 = "A"; And s2 = "AABAACAADAAE" I want it to return "BCDE" I know I'm on the rig...

Delete certain lines in a txt file via a batch file

I have a generated txt file. This file has certain lines that are superfluous, and need to be removed. Each line that requires removal has one of two string in the line; "ERROR" or "REFERENCE". These tokens may appear anywhere in the line. I would like to delete these lines, while retaining all other lines. So, if the txt file looks...

Using strcat in C

Okay so I have the following Code which appends a string to another in C#, note that this is Just an example, so giving alternative string concatination methods in C# is not nessesary, this is just to simplify the example. string Data = ""; Data +="\n\nHTTP/1.1 " + Status_code; Data += "\nContent-Type: " + Content_Type; Data += "\nServe...

C# String enums.

Hi, I have the following enumerator: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } The problem however is that I need the word "FORMS" when I ask for AuthenticationMethod.FORMS and not the id 1. I have found the following solution for this problem: First I need to create a custom at...

PHP Multiple Occurences Of Words Within A String

I need to check a string to see if any word in it has multiple occurences. So basically I will accept: "google makes love" but I don't accept: "google makes google love" or "google makes love love google" etc. Any ideas? Really don't know any way to approach this, any help would be greatly appreciated. ...

Is there a way to make "destructive" string methods a-la Ruby?

In Ruby, methods which change the object have a bang on the end: string.downcase! In c# you have to do: foo = foo.ToLower() Is there a way to make an extension method like: foo.ConvertToLower() that would manipulate foo? (I think the answer is no since strings are immutable and you can't do a ref this in an extension method.) ...

Comparing Strings in Ruby

I need to take two strings, compare them, and print the difference between them. So say I have: teamOne = "Billy, Frankie, Stevie, John" teamTwo = "Billy, Frankie, Stevie" $ teamOne.eql? teamTwo => false I want to say "If the two strings are not equal, print whatever it is that is different between them. In this case, I'm just look...