Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I think my loop have some problem. First i consider (i=0 and i>1) but i have no idea how to write. Any one can help me?
logik i want is
//start
=>if i=0 copy from txtbox1;
=>after that, compare i=2 and i=3 see whether are same. if same then copy from txtbox;
=>i++ until the last, every 1,2,3,4... will show differend string;
//end
public void OnMasterColumnChanged(BCE.AutoCount.Invoicing.Sales.SalesOrder.SalesOrderMasterColumnChangedEventArgs e)
{
for (int i = 0; i < e.MasterRecord.DetailCount; i++)
{
if (i == 0)
{
e.MasterRecord.GetDetailRecord(i).YourPONo = TxtBox1.Text;
}
else if (i > 1)
{
if (e.MasterRecord.GetDetailRecord(i).YourPONo == e.MasterRecord.GetDetailRecord(i - 1).YourPONo)
{
e.MasterRecord.GetDetailRecord(i).YourPONo = TxtBox1.Text;
}
}
}
}
I think that you want that:
public void OnMasterColumnChanged(BCE.AutoCount.Invoicing.Sales.SalesOrder.SalesOrderMasterColumnChangedEventArgs e)
{
if (e.MasterRecord.GetDetailRecord.Count == 0)
return;
e.MasterRecord.GetDetailRecord(0).YourPONo = TxtBox1.Text;
if (e.MasterRecord.GetDetailRecord.Count < 3)
return;
for (int i = 2; i < e.MasterRecord.DetailCount; i++)
{
if (e.MasterRecord.GetDetailRecord(i).YourPONo == e.MasterRecord.GetDetailRecord(i - 1).YourPONo)
{
e.MasterRecord.GetDetailRecord(i).YourPONo = TxtBox1.Text;
}
}
}
IF GetDetailRecord method returns the different values for different inputs then You are passing the different values below for the GetDetailRecord and checking the equal condition.
if (e.MasterRecord.GetDetailRecord(i).YourPONo == e.MasterRecord.GetDetailRecord(i - 1).YourPONo)
At one place you are passing GetDetailRecord(i) and checking with the GetDetailRecord(i - 1)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
the question with image
This is my code and I explained everything in the code.
Console.Write("If you write stop program will stop.");
string a;
string b = "stop";
a=Console.ReadLine(); //I try to get a value for my a string
for (int i = -3; i <= a.Length; i+=4) // try to read them with 4 length groups
{
if (a[i] == b) //and my logic was like this if it see the stop it will stop but I couldn't write it.
{
}
}
Within your function (I suppose it's the application entry point):
while (true)
{
String line = Console.ReadLine();
if ((line == null) || (line.ToLowerInvariant() == "stop"))
break;
// implement your logic here... for example, if you want to print
// a word at once even if the user entered multiples:
String[] split = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (Int32 i = 0 ; i < split.Length; ++i)
Console.WriteLine(split[i]);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Getting a byte array like this [0,0,0,0,0,1,1,1,1,3,3,3,3,0,0,0,0,0]
Does anyone know how to detect a change from 1 to 3 efficiently in linq?
Why Linq? you could achieve this with simple loop.
int previous = array[0];
for(int i=1;i< array.Length;i++)
{
if(Math.Abs(array[i]- previous) > 1) // use appropriate jump
{
//logic
}
previous = array[i];
}
If you are looking for Linq solution, you could do this.
int previous = array[0];
array.FirstOrDefault(x=>
{
var retValue = Math.Abs(x- previous) > 1;
previous = x;
return retValue;
});
If you want to find all change-indexes in the most efficient way:
List<int> changeIndexes = new List<int>();
for(int i = 1; i < array.Length; i++)
if(array[i] != array[i-1])
changeIndexes.Add(i);
Linq is not the best tool when it comes to indexes.
If you want to find only the index where 1 changes to 3 modify the condition accordingly:
if(array[i] == 3 && array[i-1] == 1) ... // break the loop if you only want to find the first
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can I check whether an array of strings has the same letter three times in a row? for example:
AABAC would return no
AAABC would return yes
Sometimes (rarely) regexes are the response to the question, especially if the question is like this.
bool ism1 = Regex.IsMatch("AABAC", #"(.)\1\1"); // false
bool ism2 = Regex.IsMatch("AAABC", #"(.)\1\1"); // true
Matches any character (.) followed by the first match (\1) twice.
bool ContainsTheSameCharThreeTimesInARow(string s) {
for (int i = 2; i < s.Length; ++i) {
if (s[i] == s[i-1] && s[i] == s[i-2])
return true;
}
return false;
}
You can just scan through the string value and check if three adjacent character are the same
public bool Contains3InARow(string data)
{
for(var i=0;i<data.Length-2;++i)
if(data[i]==data[i+1] && data[i+1]==data[i+2])
return true;
return false;
}
bool CheckStringHasRepeatForThree(string inputString)
{
if (inputString.Length < 3) return false;
return inputString.Where((c,i)=> i >= 2 && s[i-1] == c && s[i-2] == c).Any();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Currently I have multiple if-else loops in my code, such as:
if (a > 2 && a < 4)
{
// do something
}
else if (a > 4 && a < 6)
{
// do something
}
else if (a > 6 && a < 8)
{
// do something
}
... and so on.
is there a way to re-arrange this into a simpler FOR loop? or any other loop which can make the code more optimized?
for (int i = 2; ; i += 2)
{
if (a > i && a < i + 2)
{
//Do your thing
break;
}
}
You could use a switch if you wanted to check for exact values. However, since your conditions are based on mathematic expressions, you are likely better off sticking with what you've got. It may look cluttered, but it's likely already the most efficient way to do what you're trying to do.
if I understand correctly, all you need is put the values in an array as shown below and call the methods dynamically, is that what you are looking for?
var range = [3,5,7] //defined the range as >2 and <4 is equal to 3 and so on.
$.each(range, function(i, val){
window[PerformActionByVal + val]();//call the specific function
});
function PerformActionByVal3()
{
}
function PerformActionByVal5()
{
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
here is my code i want to replace dbk,depb,epcg,nfei with Demo[i]
string Test = ddlExim.SelectedItem.Text.Substring(3);
txtEximDesc.Text = ddlExim.SelectedItem.Text.Substring(3);
string[] Demo = ddlExim.SelectedValue.Split(',');
DBK.Style.Add("display", "none");
DEPB.Style.Add("display", "none");
EPCG.Style.Add("display", "none");
NFEI.Style.Add("display", "none");
for (int i = 0; i < 3; i++)
{
if (Demo[i] == "DEPB")
{
DEPB.Style.Add("display", "table-row");
}
}
}
If I understand your problem correctly then I think the simplest way would be adding a switch case. Check the code below. Please elaborate your question if this is not what you meant.
for (int i = 0; i < Demo.Length; i++)
{
switch (Demo[i].ToLower())
{
case"dbk":
DBK.Style.Add("display", "table-row");
break;
//And so on
default:
break;
}
}
OR
mark runat="server" to the table element inside which these tablerows are present ("tbl" in my example) and then try the following code.
for (int i = 0; i < Demo.Length; i++)
{
(tbl.FindControl(Demo[i]) as HtmlTableRow).Style.Add("display", "table-row");
}
Of course you need to add the following namespace.
using System.Web.UI.HtmlControls;
Hope this helps.