[Solved] searching sub string in string and check another string before that [closed]

Here ya go, use std::string::find: // Notice the double quotes std::string::size_type position = my_string.find(“34”); bool found = ((position != std::string::npos) && (position > 0) && (my_string[position – 1] == ‘6’)); The find method returns the position of substring, or std::string::npos if it is not found. The position must be greater than 0, because of the … Read more

[Solved] Me not understanding do while loops [closed]

If the number input isn’t one that you check (1 to 5) then you hit: else if (a == 1) { std::cout << “\n”; return 1; } which will enter the if (because a is 1), print a new line and return from main ending your run. solved Me not understanding do while loops [closed]

[Solved] Remove empty properties from object in list in C#

You cannot achieve this if you want to stay with your custom type. Reason is that if you define a type with some properties then when initializing that type the properties are there, whether you assign to them a value or not. However using anonymous types and dynamic you can: var result = data.Select(item => … Read more

[Solved] C program goes into infinite loop with scanf [duplicate]

Check return value of scanf and clear input buffer in case of illegal input. Like this: #include <stdio.h> #include <stdbool.h> int main(void) { float sales, commission, earnings; int state; while(true) { printf( “Enter sales in dollars ( -1 to end ): ” ); if((state = scanf(“%f”, &sales )) != 1){ if(state == EOF) return 0; … Read more

[Solved] C#: Read data and add it to a list

This should do it… (for MSSQL, but apart from the connection the principal is the same) private List<short> SQLColumnsToList() { using (var conn = new SqlConnection(/*Your connection string here*/)) using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = “select * from db2prod.questions where key_id = @keyID”; cmd.Parameters.AddWithValue(“keyID”, /*Your ID here*/); conn.Open(); using (var … Read more

[Solved] Why some C API doesn’t follow Encapsulation

Consider the following two API variants: struct point get_location(const foo *f) { struct point p; p.x = f->something_x; p.y = f->something_y; return p; } versus: double get_location_x(const foo *f) { return f->something_x; } double get_location_y(const foo *f) { return f->something_y; } I claim there is nothing “more encapsulated” about the latter than the former. It’s … Read more

[Solved] Create xml file with dataset like this format

If you want to create some custom xml that you can use XElement. How to create <_XPXML Note=”” CrtTime=”” CN=”” DBN=”” Srv=”” Ver=”” AppId=”” Class=”” IC=”” Stock=”” Desc=””>? You can use the code below to create. var node=new XElement(“_XPXML “); node.SetAttributeValue(“Note”,””); node.SetAttributeValue(“CrtTime”,””); // … // please write the Attribute doc.Root.Add(node); Before you use the code … Read more

[Solved] Inheritance – Tricky OOP Concepts

This is actually easy to test However Static Constructors (C# Programming Guide) A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced. Static constructor is called … Read more

[Solved] I need help in c++ [closed]

You will need to use something like std::cin to take users input. Use something like a std::string container to hold the alphabetic answer i.e. yes or y. Then check your input against your control and conditionally print Hello World. #include <iostream> #include <string> int main() { std::string ans; std::cout << “Would you like to see … Read more

[Solved] stopping a thread in windows [closed]

Using the TerminateThread function. The function you posted does: PostThreadMessage(hookThreadId, WM_QUIT, (WPARAM) NULL, (LPARAM) NULL); WaitForSingleObject(hookThreadHandle, 5000); So it sends a quit message to that thread, and then waits for it to close. 6 solved stopping a thread in windows [closed]

[Solved] How to print numbers in the following pattern with .NET

The problem is in the MakeALine method. You actually concat the number with itself, so for input 1 you actually get “1” + “1”. Instead you should repeat the string representation of your number k times. For this you can use Enumerable.Repeat in the following way: static string MakeALine(int k) { return String.Concat(Enumerable.Repeat(k.ToString(),k)); } 3 … Read more