Monday, 24 November 2014

F452 - String manipulation (c#)


MODULUS:
MOD or % 
the remainder when dividing one number by another
e.g 7 MOD 3 = 1

DIV 
the whole number result
e.g 47 DIV 10 = 4


\r end of line.

\n new line.


Concatenation:
string.Concat(string, "part being added");

Replace:
string.Replace(string, "New string.\n");

Format:
string,Format("{0}: {1:0,0} - {2:yyyy}");

Turning stuff into strings:
datatype.ToString();

Turning strings into integers:
//CAUTION; HANDLE WITH CARE 
(characters cannot be converted)//
int.Parse(text);


A = 1, B = 1 }

AND
&&
e.g IF ((A==2)&&(B==3))
Returns FALSE or 0

OR
||
e.g IF ((A==2)||(B==3))
Returns False or 0

NOT
!
e.g IF (!(A==2))
Returns True or 1


Concatenation
Means joining one or more strings together.

Replace
Lets you replace a given char in a string with another character.

Extract
Returns part of the strings from between two specified elements.

Length
Returns the number of characters in a string.

charCodeAt
Returns the ASCII value of a given element.

SWAP
Swaps two given chars.

HANDY FACTOID:
In ASCII the char A is given the code 65.

Validation:


Presence check:
Is the data present, has the required field been completed?

Length check:
Is the data a suitable length?

Format check:
Correct format? e.g dd/mm/yyyy

Range check:
Is the data in the correct range.

Existence check:
Does the data match something that already exists in the system?




No comments:

Post a Comment