string

C# compare strings - Different codepage

I have two strings read in from textfiles to compare and when I try to compare these files with winmerge or pspad, they both show as the same text strings. If I compare them with the following function, it fails: string string1 = File.ReadAllText(@"c:\file1.txt"); string string2 = File.ReadAllText(@"c:\file2.txt"); bool stringMatch ...

Handling .Net UTF-8 strings in Erlang

Hello, I'm playing a bit with erlang and the distributed db Mnesia. One of the first problem I'm facing is the incompatibilty beetween the 'int list' strings of erlang and .Net UTF-8 strings. Is there any good conversion library? Thanks ...

Testing for Japanese/Chinese Characters in a string

I have a program that reads a bunch of text and analyzes it. The text may be in any language, but I need to test for japanese and chinese specifically to analyze them a different way. I have read that I can test each character on it's unicode number to find out if it is in the range of CJK characters. This is helpful, however I would l...

Whats the difference between these two strings?

Using nUnit to test the output (currency formatting) for a specific culture but we are getting the following result. Fail: Formatting currency amount String lengths are both 11. Strings differ at index 2. Expected: "12 765,87 €" But was: "12 765,87 €" -------------^ We can't see the difference between the strings. Our expec...

Rotate a string in c++?

I'm looking for a way to rotate a string in c++. I spend all of my time in python, so my c++ is very rusty. Here is what I want it to do: if I have a string 'abcde' I want it changed to 'bcdea' (first character moved to the end). Here is how I did it in python: def rotate(s): return s[1:] + s[:1] I'm not sure how to do it in cpp....

Getting rid of spaces in a string

To add a whitespace seperator in a string we use String.Join(). My question:What(and how) do I have to remove that seperator. The string's structure is the following "FF FF FF FF FF FF FF FF FF...." How do I remove the white spaces? ...

Is extending String class with IsNullOrEmpty confusing?

Everyone knows and love String.IsNullOrEmpty(yourString) method. I was wondering if it's going to confuse developers or make code better if we extend String class to have method like this: yourString.IsNullOrEmpty(); Pro: More readable. Less typing. Cons: Can be confusing because yourString variable can be null and it looks li...

Question about array shallow copy in C#

Just to make sure I'm understanding shallow copies of reference types correctly and that I'm not constructing a huge memory leak here: // Adds text to the beginning of the log RTB // Also keeps the log RTB trimmed to 100 lines var lines = new string[rtbLog.Lines.Length + 1]; lines[0] = "text"; Array.Copy(rtbLog.Lines, 0, lines, 1, rtbLo...

Determine if a string is a valid IP address in C

Hey everybody, What would be a good way to determine if a string contains an IP address. Should I use isdigit()? Suggestions would be appreciate it. Thanks ...

Why is String's format(Object... args) defined as a static method?

I wonder why Java 5 and above provide a printf-style formatter using a static method in class String like this: public static String format(String format, Object... args) instead of public String format(Object... args) so that we can write "%02d".format(5) to get 05 instead of String.format("%02d", 5). I imagined if I could modi...

A method to reverse effect of java String.split()?

I am looking for a method to combine an array of strings into a delimited String. An opposite to split(). I've seen this in other languages. Wanted to ask the forum before I try writing my own( since the JDK has everything...) Thanks, ...

Strange C++ std::string behavior... How can I fix this?

Hi All! This is driving me nuts. I have been at it for over 2 hours trying to figure this out... Here is my problem. I am working on a fairly large program that works with Bayesian networks. Here is the main function: using namespace std; int main() { DSL_network net; initializeNetwork(net); setEvidence(net); ne...

Batch file to search for string in most recent file

Hello I have alot of log files which need searching for certain strings and was wondering if I could make a batch file to automate this job for me? All I need it to do is locate the most recent log in a certain directory then search for the string in that file. I have found the below code on this website which works great to open the m...

How do I declare an array of strings in C++?

In C++ how can I declare an array of strings? I tried to declare it as an array of char but that was not correct. ...

string formatting

I am not getting why the colon shifted left in the second time >>> print '%5s' %':' : >>> print '%5s' %':' '%2s' %':' : : Help me out of this please ...

How to determine a strings dna for likeness to another

I am hoping I am wording this correctly to get across what I am looking for. I need to compare two pieces of text. If the two strings are alike I would like to get scores that are very alike if the strings are very different i need scores that are very different. If i take a md5 hash of an email and change one character the hash change...

Is this the best way in C# to convert a delimited string to an int array?

Given the string below: string str = "1,2,3"; Will this be the best extension to convert it to an int array? static class StringExtensions { public static int[] ToIntArray(this string s) { return ToIntArray(s, ','); } public static int[] ToIntArray(this string s, char separator) { string[] ar = s.S...

Returning a std::string from a C++ DLL to a c# program -> Invalid Address specified to RtlFreeHeap

Hi, In a function in my C++ DLL, I'm returning a std::string to my c# application. It pretty much looks like this: std::string g_DllName = "MyDLL"; extern "C" THUNDER_API const char* __stdcall GetDLLName() { return g_DllName.c_str(); } But when my C# code calls this function, I get this message in my output window: Invalid Add...

Regex for set

I'd like some help for detecting the following expressions with RegEx string "(x/x)" where x is any number from 0-999. string "x of x" where x is any number from 0-999. Typically, the string is a marker for a set, i.e. 4 of 10 things, or (3/5) where the first number is the item and the second number is the total. Thanks ...

Creating a comma separated list from IList<string> or IEnumerable<string>

What is the cleanest way to create a comma-separated list of string values from an IList<string> or IEnumerable<string>? String.Join(...) operates on a string[] so can be cumbersome to work with when types such as IList<string> or IEnumerable<string> cannot easily be converted into a string array. ...