string

dynamic string localization in WPF

I have a C#/WPF application and I am attempting to add multi-language support. From my looking around I've found that using resource files of string values for each language is how I should go about doing this. Then update the CultureInfo. This seems to work fine if the culture info is set at or before the creation of the window, but I w...

Cut off the filename and extension of a given string.

I build a little script that parses a directory for files of a given filetype and stores the location (including the filename) in an array. This look like this: def getFiles(directory) arr = Dir[directory + '/**/*.plt'] arr.each do |k| puts "#{k}" end end The output is the path and the files. But I want only the path. Inste...

Is there a method in python that's like os.path.split for other delimiters?

I want to use something like this: os.path.split("C:\\a\\b\\c") With this kind of output: ('C:\a\b', 'c') However I want it to work on other delimiters like this: method ('a_b_c_d') With this kind of output: ('a_b_c', 'd') ...

How do I force showing '+' sign using StringFormat

Is there a way to force showing the + sign in front of positive numbers when using StringFormat? For example: <TextBlock Text="{Binding Path=PercentAgainstBudget, StringFormat={}{0:0.00}%}" /> If PercentAgainstBudget is negative I see the - sign. But if its positive, it does not. Since this number is an off...

Is there a difference between String concat and the + operator in Java?

Duplicate java String concatenation I'm curious what is the difference between the two. The way I understand the string pool is this: This creates 3 string objects in the string pool, for 2 of those all references are lost. String mystr = "str"; mystr += "end"; Doesn't this also create 3 objects in the string pool? String mys...

What is the best way to add two strings together?

I read somewehere (I thought on codinghorror) that it is bad practice to add strings together as if they are numbers, since like numbers, strings cannot be changed. Thus, adding them together creates a new string. So, I was wondering, what is the best way to add two strings together, when focusing on performance? Which of these four is ...

Best way to implement conditional in a PHP templating system?

I'm creating a very simple PHP templating system for a custom CMS/news system. Each article has the intro and the full content (if applicable). I want to have a conditional of the form: {continue}click to continue{/continue} So if it's possible to continue, the text "click to continue" will display, otherwise, don't display this whole...

split string based on regexp

Hi, I want to split a string in C# that looks like a : b : "c:d" so that the resultant array will have Array[0] = "a" Array[1] = "b" Array[2] = "c:d" what regexp do I use to achieve the required result. Many Thanks ...

.NET object hydration from IDataReader slow performance

I am trying to hydrate a list of ~400 business objects and the performance becomes very slow when it needs to hydrate strings. It's taking in excess of 20secs to hydrate the 400 objects. EDIT We are using MySQL 5.1 and dotConnect for MySQL v5.0.12 as the data provider http://www.devart.com/dotconnect/mysql/ I did some benchmarks to na...

Why is this appearing in my c# strings: £

I have a a string in c# initialised as follows: string strVal = "£2000"; However whenever I write this string out the following is written: £2000 It does not do this with dollars. An example bit of code I am using to write out the value: System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("/logging.txt"), strVal); I...

String casts

Hi Why is there so may ways to convert to a string in .net? The ways I have seen are .ToString, Convert.ToString() and (string). What is the Difference. ...

Print out Linq Expression Tree Hierarchy

The DLR has some pretty cool code for Expression's, including some very nice code to print out Expression trees which I want to use so that: int a = 1; int b = 2; Expression<Func<int, int>> expression = (c) => a + (b * c) expression.Evaluate(5, stringBuilder) Outputs: (5) => a + (b * c) = 11 Where a = 1 b * c = 10 Where ...

Can other datatypes than Strings be potentially harmful if obtained from external sources?

It's a well known truth, that you don't can trust user inputs. These inputs can be even an security-problem, if they are used unfiltered. XSS and SQL-injections are possible problems coming from using unfiltered user-input (or input, that can be changed by the user). To avoid such problems, you have to control all strings, that can be i...

Making rails do variable replacement from a db string

I have a string in a db that contains a local variable reference and I want Ruby to parse and replace it. For example, the string in the db is "Hello #{classname.name}" and it is stored in classname.description and my code reads: <%=h @classname.description %> Put that just prints the exact value from the db: Hello #{name} and not...

Format a number as a string

How do you format a number as a string so that it takes a number of spaces in front of it? I want the shorter number 5 to have enough spaces in front of it so that the spaces plus the 5 have the same length as 52500. The procedure below works, but is there a built in way to do this? a = str(52500) b = str(5) lengthDiff = len(a) - len(...

Best way to build object from delimited string (hopefully not looped case)

Hi - this question feels like it would have been asked already, but I've not found anything so here goes... I have constructor which is handed a string which is delimited. From that string I need to populate an object's instance variables. I can easily split the string by the delimited to give me an array of strings. I know I can simply...

How do I execute a string containing Python code in Python?

How do I execute a string containing Python code in Python? ...

Is it because of string pooling by CLR or by the GetHashCode() method?

Hi all, Is it because of string pooling by CLR or by the GetHashCode() method of both strings return same value? string s1 = "xyz"; string s2 = "xyz"; Console.WriteLine(" s1 reference equals s2 : {0}", object.ReferenceEquals(s1, s2)); Console writes : "s1 reference equals s2 : True" I believe that, it's not because of the GetHashCod...

Mathematica StringReplace to replace a substring containing newlines.

I have something like the following in a string: blah blah BEGINIGNORE this stuff should get stripped out ENDIGNORE more stuff here I would like to do this (perl syntax): s/BEGINIGNORE.*ENDIGNORE//s -- namely, strip out everything between BEGINIGNORE and ENDIGNORE, inclusive. You would think the following would do that in Mathema...

How to nicely format floating types to String?

An 64-bit double can represent integer +/- 253 exactly Given this fact I choose to use a double type as a single type for all my types, since my largest integer is unsigned 32-bit. But now I have to print these pseudo integers, but the problem is they are also mixed in with actual doubles. So how do I print these doubles nicely in Jav...