new-operator

C# Regex Match any text between tags including new lines

不羁的心 提交于 2019-12-10 16:37:54
问题 Here is my regex: \[\[START\]\]\[\[OK\]\](.*?)\[\[END\]\] I want to get any text contained in [[START]][[OK]] and [[END]] . However when my text contains some \r\n characters, my regex doesn't match it. How can it make it work? 回答1: Use single-line mode http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx#Singleline 回答2: I don't know for sure if this works for RegEx'es as well,but you could try using Environment.NewLine in stead of \r\n. 来源: https://stackoverflow.com/questions/6179116/c

How to create an array while potentially using placement new

被刻印的时光 ゝ 提交于 2019-12-10 14:26:20
问题 I have been working on creating a custom allocator as a fun exercise/practice and I ran into two potentials issues with creating arrays. For a typical call for allocation, I will use malloc and placement new . However, when I go to create an array I am confused on how it should be done. For once, I have noticed at some places that it seems placement new may not be safe for arrays such as here. I am also running into an error of my own while attempting to use placement new for an array. I will

Using sentinal values in C# enum (size of enum at compile time)?

别来无恙 提交于 2019-12-10 14:26:08
问题 A shortcut I often use in C when dealing with embedded APIs (communications protocols, primarily) allows me to edit an enum array and have everything else sized correctly after that: typedef enum { errortype1, errortype2, ... errortypeN, ERROR_TYPE_MAX } ErrorTypeList; int errorcounts[ERROR_TYPE_MAX]; // Create array to hold a counter for each error type As long as I add new error types before ERROR_TYPE_MAX then I can use that value everywhere else to give me the size of the enum. In C#,

In R, how to get the whole command line into the sys.call() of a binary operator?

假装没事ソ 提交于 2019-12-10 13:18:34
问题 I wrote a binary operator function for R (i.e. one with a name like %X% so that instead of having to type %X%(a,b) I can use the more convenient syntax a %X% b . My goal is to have a wrapper for <- that does things like log what was done to objects in that environment and check for a 'protected' attribute which would warn the user before overwriting that object. All of this works, except that if I try do do something like a %X% b + c inside the function all you see is a %X% b _and that is

referencing multiple foreign keys php mysql

风格不统一 提交于 2019-12-10 11:41:56
问题 I'm very new to php/MySQL and I'm having a bit of trouble. Help would be much appreciated. I have 2 tables laid out as such: table team team_id,team_name table schedule game_id,game_time,team1_id,team2_id,location schedule.team1_id and schedule.team2_id are both foreign keys to team.team_id. I'm trying to reference team_name using team1_id and team2_id but I can only ever seem to get the name for team1. This is the query I've used unsuccessfully. SELECT * FROM team AS t JOIN schedule AS s ON

VB.NET Dim vs. New

故事扮演 提交于 2019-12-10 10:51:36
问题 What are the differences between the following constructs? Why prefer one over the other? Number one: Dim byteArray(20) as Byte Number two: Dim byteArray() as Byte = new Byte(20) {} Any help would be appreciated. Thank you. Edit - I corrected some code. "ReDim" should be "Dim". 回答1: They both allocate 20 bytes on the managed heap. They both set the identifier 'byteArray' to point to those bytes. The statement with the "new" operator (clause) allows initialization of the array elements. Dim

Instantiate an array of objects, in simpliest way?

ぐ巨炮叔叔 提交于 2019-12-10 10:45:40
问题 Given a class: class clsPerson { public int x, y; } Is there some way to create an array of these classes with each element initialized to a (default) constructed instance, without doing it manually in a for loop like: clsPerson[] objArr = new clsPerson[1000]; for (int i = 0; i < 1000; ++i) objArr[i] = new clsPerson(); Can I shorten the declaration and instantiation of an array of N objects? 回答1: You must invoke the constructor for each item. There is no way to allocate an array and invoke

Problem adding Contact with new API

倾然丶 夕夏残阳落幕 提交于 2019-12-10 10:43:05
问题 I am trying to add a new contact to my contact list using the new ContactContract API via my application. I have the following method based on the Contact Manager example on android dev. private static void addContactCore(Context context, String accountType, String accountName, String name, String phoneNumber, int phoneType) throws RemoteException, OperationApplicationException { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); //Add contact type ops.add

In Java what happens when an object fails to be instantiated?

眉间皱痕 提交于 2019-12-10 03:24:22
问题 I come from a c++ background and I find myself constantly doing this in java: SomeClass sc=new SomeClass(); if(null!=sc) { sc.doSomething(); } What I want to know is what will be in the variable sc if the constructor fails for some reason (like maybe not enough memory). I can' t find a straight answer, and I am worried that I am just wasting my time because maybe if the new operator fails would the program just crash anyway? 回答1: The Java Specification Language 3rd Edition covers your

Scala: companion objects and “new” keyword

大兔子大兔子 提交于 2019-12-10 03:09:31
问题 In my recent posts about using or omitting a "new" keyword in Scala ( "new" keyword in Scala) I was told that the omission comes from the fact that certain classes have companion objects defined with apply method on them. My question is: are we able to tell or is there any general rule to distinguish which classes/objects have a companion object and apply method? Thanks in advance and sorry of it's a stupid question, but coming from a Java background it is a bit confusing. 回答1: In the Scala