Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
AnswerRe: csharp creating algorithm Pin
BillWoodruff12-Apr-16 23:47
professionalBillWoodruff12-Apr-16 23:47 
GeneralRe: csharp creating algorithm Pin
OriginalGriff13-Apr-16 0:10
mveOriginalGriff13-Apr-16 0:10 
GeneralRe: csharp creating algorithm Pin
Richard MacCutchan13-Apr-16 0:44
mveRichard MacCutchan13-Apr-16 0:44 
GeneralRe: csharp creating algorithm Pin
BillWoodruff13-Apr-16 3:02
professionalBillWoodruff13-Apr-16 3:02 
GeneralRe: csharp creating algorithm Pin
Sascha Lefèvre13-Apr-16 3:51
professionalSascha Lefèvre13-Apr-16 3:51 
GeneralRe: csharp creating algorithm Pin
BillWoodruff13-Apr-16 5:02
professionalBillWoodruff13-Apr-16 5:02 
AnswerRe: csharp creating algorithm Pin
Patrice T13-Apr-16 9:14
mvePatrice T13-Apr-16 9:14 
Questionpuzzle, sub string not working Pin
Member 1016760412-Apr-16 21:20
Member 1016760412-Apr-16 21:20 
C#
Hi,
I was given following question as an assessment but unfortunately I was unable to answer. Can someone help ?
The question is ;
The function given below is supposed to retrieve the substring between and including the ith and jth characters of the input string s.  When i and j are out of range, ie. i,j< 0 ori,j >= s.length(), the function returns the string "<error>". The following table shows the expected and actual return values of the function for various inputs.


C#
Test case	s	      i	j	Expected return value	Actual return value
1	        "quick"	  0	2	"qui"	                 "qui"
2	        "brown"	  2	1	"ro"	                 ""
3	        "fox"	  1	9	"<error>"	             "<error>"
4	        "jumped"  -1	4	"<error>"	             "<error>"
5	        "lazy"	  3	0	"lazy"	                 "<error>"
6	        "dog"	  1	1	"o"	                     "o"


Unfortunately, the function returns the wrong value for the 2nd and 5th test cases.

C#
C# Version:
string SubString(string s, int i, int j)
{
      int k;
string result;
      try
      {
            k = s.Length;
            if (i < 0 || j < 0 || i >= k || j >= k)
                  throw new Exception();
            result = s.Substring(i, j + 1 - i);
      }
      catch (Exception e)
      {
            return "<error>";
      }
return result;
}
a) Under what general conditions does the function return the wrong value? 
 
b) Add some code to fix the function. Can you improve it? If so explain why your version is better.

AnswerRe: puzzle, sub string not working Pin
Richard MacCutchan12-Apr-16 21:25
mveRichard MacCutchan12-Apr-16 21:25 
QuestionCould not load file or assembly Pin
RAFish040412-Apr-16 8:26
RAFish040412-Apr-16 8:26 
AnswerRe: Could not load file or assembly Pin
Richard MacCutchan12-Apr-16 10:01
mveRichard MacCutchan12-Apr-16 10:01 
QuestionHow add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri11-Apr-16 21:50
srikrishnathanthri11-Apr-16 21:50 
AnswerRe: How add a custom menu to Windows Explorer's tool bar Pin
Pete O'Hanlon11-Apr-16 22:22
mvePete O'Hanlon11-Apr-16 22:22 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri12-Apr-16 3:51
srikrishnathanthri12-Apr-16 3:51 
QuestionRe: How add a custom menu to Windows Explorer's tool bar Pin
CHill6012-Apr-16 5:52
mveCHill6012-Apr-16 5:52 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
Eddy Vluggen12-Apr-16 5:59
professionalEddy Vluggen12-Apr-16 5:59 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri12-Apr-16 23:40
srikrishnathanthri12-Apr-16 23:40 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
Eddy Vluggen13-Apr-16 0:05
professionalEddy Vluggen13-Apr-16 0:05 
GeneralRe: How add a custom menu to Windows Explorer's tool bar Pin
srikrishnathanthri13-Apr-16 1:14
srikrishnathanthri13-Apr-16 1:14 
QuestionRar and c# Pin
Sakeb11-Apr-16 20:24
Sakeb11-Apr-16 20:24 
SuggestionRe: Rar and c# Pin
Richard MacCutchan11-Apr-16 21:30
mveRichard MacCutchan11-Apr-16 21:30 
AnswerRe: Rar and c# Pin
OriginalGriff11-Apr-16 21:38
mveOriginalGriff11-Apr-16 21:38 
AnswerRe: Rar and c# Pin
koolprasad200311-Apr-16 22:50
professionalkoolprasad200311-Apr-16 22:50 
QuestionMass Storage USB device protection tool except few white list USB hard disk Pin
Deepeshonly11-Apr-16 7:19
Deepeshonly11-Apr-16 7:19 
QuestionRe: Mass Storage USB device protection tool except few white list USB hard disk Pin
CHill6011-Apr-16 12:52
mveCHill6011-Apr-16 12:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.