It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Function receives char[,].
For example if it it takes
000
LAD
0B0
Traversing should print out all possible combinations of non-zero chars:
L
LA
LAD
LAB
A
AL
AB
AD
and so on
private void Traverse(char[,] area)
{
}
The easiest way is to write a recursive function with two strings, initial and output. I assume you want combinations, not permutation so it's a little easier. The base case is checking if initial is empty, then print out the output. The step is removing a character from initial and calling the recursive function twice, one with the unchanged output and one with the removed character added into the output. If the removed character is 0, however, then you only call the function once (removing the 0 without adding anything to the output.)
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
The input string: A+SUM(A)C+AB-C+SUM(A)+1
I want to replace A with 0, the result like this:0+SUM(A)C+AB-C+SUM(A)+1
or replace SUM(A) with 0, the result like this:A+SUM(A)C+AB-C+0+1
Thanks
Without Regex (because Regex is overkill for this):
var s = "A+SUM(A)+B-C";
var replaceBeginningA = s.Replace("A+", "0+");
var replaceSumA = s.Replace("SUM(A)", "0");
Console.WriteLine(replaceBeginningA); // 0+SUM(A)+B-C
Console.WriteLine(replaceSumA); // A+0+B-C
As pointed out in the comments though, you need to provide more detail if this input is expected to have a different format.
maybe:
replace ^A with 0
replace SUM\(A\) with 0
Try thus:
string replaced = Regex.Replace(input, #"\b(\w+)\+SUM\(\1\)", "0+0");
This will match anything of the form
foo+SUM(foo)
and replace it with 0+0
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
H iguys. I have a loop which parse users id's and adds tham to txt file.
What's the best way than to check if this txt has this id skip it ( while next parsing ).
The size of txt rises from 5-..... mb
I tried to add ids to List, but when the size of file if bigger than 5mb the app begins hanging
Use a HashSet<int> or HashSet<string>, collect the ids in it, then at the end write the result to the text file.
PS: Note that HashSet is O(1) while List is O(n)
You should probably load all of the IDs in the text file into some collection and check if that collection contains the IDs.
I honestly don't think that there's a much more efficient way of doing it than that.
A rule of thumb I believe is to trade time with space. If you want to make copying faster and avoid looking into the file again and again then you may maintain an array or linked list or hash table which also have the id stored in it
var userIsAlreadyThere = File.ReadLines(path).Contains(userid);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
So I have this
Random random1 = new Random();
int intrandom1 = random1.Next();
I want to put a long after the .Next. How do I do that? It only accepts ints.
First idea: A long as 64 bit integer, is the combination of 2 32 bit integers, so you can use:
((long)random1.Next() << 32) | random1.Next()
Or perhaps
((long)random1.Next() <<< 32) | random1.Next()
if you use java (?) and need a unsigned shift
edit: does not look like Java. Java has random1.nextLong() for that. Perhaps C#? I do not know that
It can be generated arbitrary long number by using a simple linked list. Just imagine that every node from list can store a number random generated, and a function can be read that list like an unitary number. Using an algorithm like that you can obtain an arbitrary long random number.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a list and a column; the column might have many values, and each value's length may vary.
If the length exceeds 100, I want to append /n at the end of it.
Need your help.
I give it a try, though a lot of questions are open (what type of list, what a column, ...).
In short: you can use String.Insert to insert text at a specified postition.
Assuming you have a List<Foo>, the class Foo has a string property Value (your column). If it's Length exceeds 100 the line should be wrapped:
foreach(Foo foo in foos)
{
if(foo.Value.Length > 100)
foo.Value = foo.Value.Insert(100, Environment.NewLine);
}
http://msdn.microsoft.com/en-us/library/system.string.insert.aspx
Here's running code with sample data.
http://ideone.com/sUKLk
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Scenario:
I have to check for user input (a string) that shouldn't contain <.%?/ symbols and if it does I remove them. I have 20 different places where I've to check it, actually, 20 different pages with each 20 different controls.
So I wrote a function like the following shortened example:
public string MyFunction (string userinput)
{
return userinput.replace("<"," ");
}
Now if I want to call this function from within another function and there's an error in this function's try catch block I want it to write an error to a Label on the main page, without interrupting the second function.
Also i am thinking of implementing conditional statement function calls too.
Usually it's best to let the calling function catch your error and to act upon it. Something like this (assuming C#, but your question wasn't clear about that and didn't have a working example):
try {
string resplacedString = yourReplaceFunction(userInput);
} catch (MyException e) {
Label1.Text = "An error occurred." + e.Description;
}