string

Checking for null before ToString()

Here's the scenario... if (entry.Properties["something"].Value != null) attribs.something = entry.Properties["something"].Value.ToString(); While effective and working correctly, this looks ugly to me. If I don't check for a null before performing the ToString() then it throws an exception if the property was null. Is there a be...

C#: Strings with same contents

I have heard and read that a string can not be changed (immutable?). That should be correct I guess. But I have also heard that two strings with the same contents share the same memory-space (or what you call it). Is this correct? And if so, does that mean that if I create a List with thousands of strings, it wouldn't really take up muc...

What's the @ in front of a string for .NET?

This is a .NET question for C# (or possibly VB.net), but I am trying to figure out what's the difference between the following declarations: string hello = "hello"; vs. string hello_alias = @"hello"; Printing out on the console makes no difference, the length properties are the same. Thanks! ...

Trim / remove a tab ( "\t" ) from a string

Can anyone suggest a way of stripping tab characters ( "\t"s ) from a string? CString or std::string. So that "1E10      " for example becomes "1E10". Thanks in anticipation. ...

Bit Operation For Finding String Difference

Dear all, The following string of mine tried to find difference between two strings. But it's horribly slow as it iterate the length of string: #include <string> #include <vector> #include <iostream> using namespace std; int hd(string s1, string s2) { // hd stands for "Hamming Distance" int dif = 0; for (unsigned i = 0;...

How to join strings in PHP?

I have three strings: $str1 = "abc"; $str2 = "def"; $str3 = "ghi"; I can get the value of all of them like this: echo "$str1$str2$str3"; But I heard there is a way to join them together, so I can echo all of them without quotes. ...

String separation in required format, Pythonic way? (with or w/o Regex)

I have a string in the format: t='@abc @def Hello this part is text' I want to get this: l=["abc", "def"] s='Hello this part is text' I did this: a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.split('@') l=[i.strip() for i in b][1:] It works for the most part, but it fails when the text part h...

How do I parse a token from a string in C?

How do i parse tokens from an input string. For example: char *aString = "Hello world". I want the output to be: "Hello" "world" ...

What makes more sense - char* string or char *string?

Duplicate of this question. I'm learning C++ at the moment, and I'm coming across a lot of null-terminated strings. This has got me thinking, what makes more sense when declaring pointers: char* string or char *string ? To me, the char* format makes more sense, because the type of "string" is a pointer to a char, rather than a cha...

Mysql: Using LIKE vs. = for exact string match

First off, I recognize the differences between the two: - Like makes available the wildcards % and _ - significant trailing whitespace - colation issues All other things being equal, for an exact string match which is more efficient: SELECT field WHERE 'a' = 'a'; Or: SELECT field WHERE 'a' LIKE 'a'; Or: Is the difference so insign...

How to strip HTML attributes except "src" and "alt" in JAVA

Hi, problem: How do I strip all attributes from HTML tags in a string, except "alt" and "src" using Java? And further.. how do I get the content from all "src" attributes in the string? :) ...

Can I pass parameters to String.Format without specifying numbers?

Is there a way to String.Format a message without having to specify {1}, {2}, etc? Is it possible to have some form of auto-increment? (Similar to plain old printf) ...

In Java, how do I parse XML as a String instead of a file?

I have the following code: DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile); How can I get it to parse XML contained within a String instead of a file? ...

When is it a good use of time to refactor string literals?

I'm starting on a project where strings are written into the code most of the time. Many strings might only be used in a few places but some strings are common throughout many pages. Is it a good use of my time to refactor the literals into constants being that the app is pretty well established and runs well? What would be the long-t...

Format Repeating Decimal as a Fraction

I need to convert decimal values to their fractional equivalents, similar to this previous question. I'm using the code posted in one of the answers as a starting point since it mostly does what I need it to do. string ToMixedFraction(decimal x) { int whole = (int) x; int denominator = 64; int numerator = (int)( (x - whole) * denomina...

Iterating over substrings of equal size

I want to convert my String object to Enumerable of its 1-sized substrings (not chars), how can I do this efficiently in Ruby? ...

How would you implement your string type?

Assume you are designing and implementing a new language from scratch, though you may freely borrow ideas from existing languages/implementations. Question: If a programmer declares a string variable (assume strongly typed), how would you choose to store this variable in memory? There are many use cases, but do you have a particular mo...

Does any one know of a faster method to do String.Split()?

I am reading each line of a CSV file and need to get the individual values in each column. So right now I am just using: values = line.Split(delimiter); where line is the a string that holds the values that are seperated by the delimiter. Measuring the performance of my ReadNextRow method I noticed that it spends 66% on String.Split,...

Finding all string in a PHP code base

I have a few-million-line PHP code base without true separation of display and logic, and I am trying to extract all of the strings that are represented in the code for the purposes of localization. Separation of display and logic is a long term goal, but for now I just want to be able to localize. In the code, strings are represented ...

Putting spaces back into a string of text with unreliable space information

I need to parse some text from pdfs but the pdf formatting results in extremely unreliable spacing. The result is that I have to ignore the spaces and have a continuous stream of non-space characters. Any suggestions on how to parse the string and put spaces back into the string by guessing? I'm using ruby. Or should I say I'musingrub...