return only Digits 0-9 from a String
In .NET, you could extract just the digits from the string. Using Linq like this: string justNumbers = new String(text.Where(Char.IsDigit).ToArray()); Don’t forget to include using System.Linq
In .NET, you could extract just the digits from the string. Using Linq like this: string justNumbers = new String(text.Where(Char.IsDigit).ToArray()); Don’t forget to include using System.Linq
Imagine a guy who builds cars. Say it’s the same thing as using a computer. At some point he realizes he’s always doing the same thing, more or less. So he builds factories to build cars, and it’s much better. He’s now programming ! Nevertheless, once again, at some point, he realizes he’s always doing … Read more
Use the Replace Constructor with Builder refactoring. To use this function, click on the constructor’s signature in your code, then right click and select the “Refactor” menu, then click “Replace Constructor with Builder…” to bring up the dialog box to generate the code.
Why do PHP Array Examples Leave a Trailing Comma? Because they can. 🙂 The PHP Manual entry for array states: Having a trailing comma after the last defined array entry, while unusual, is a valid syntax. Seriously, this is entirely for convenience so you can easily add another element to the array without having to … Read more
Here is the solution I have been using for such cases. It is useful when you have auto-generated classes that you want to decorate with attributes. Let’s say this is the auto-generated class: public partial class UserProfile { public int UserId { get; set; } public string UserName { get; set; } public string Firstname … Read more
There are two issues here: Yes, you can run the Razor View Engine outside of the context of an ASP.NET app domain, as explained in Andrew’s blog: http://vibrantcode.com/blog/2010/11/16/hosting-razor-outside-of-aspnet-revised-for-mvc3-rc.html However, Razor is still primarily focused on generating xml-like markup (e.g. HTML) in the sense that the Razor parser uses the presence of <tags> to determine the … Read more
I use . separation – for example EmployeeController.SomeSpecialBehaviour.cs. I also link it into the project tree via “dependentUpon” or whatever it is in the csproj, so that it nests under the file (in solution explorer) neatly. You have to do that by hand (edit the csproj) or with an addin, though; for example: <Compile Include=”Subfolder/Program.cs” … Read more
Saving it in source control is more trouble than it’s worth. You have to do a commit every time you do a build for it to be any value. Generally we leave generated code( idl, jaxb stuff, etc) outside source control where I work and it’s never been a problem
Scaffolding generally refers to a quickly set up skeleton for an app. It’s not rails-only since other platforms have it as well. It’s also not generally meant to be a “final” system; merely the first, smallest way to do it.
Where: class Teacher < ActiveRecord::Base has_and_belongs_to_many :students end and class Student < ActiveRecord::Base has_and_belongs_to_many :teachers end for rails 4: rails generate migration CreateJoinTableStudentTeacher student teacher for rails 3: rails generate migration students_teachers student_id:integer teacher_id:integer for rails < 3 script/generate migration students_teachers student_id:integer teacher_id:integer (note the table name lists both join tables in alphabetical order) and … Read more