Google
 
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, May 14, 2010

String Manipulation Functions in VB - Len, Right, Left, Mid, Trim, Ltrim, Rtrim, Ucase, Lcase, Instr, Val, Str ,Chr and Asc

Here's how to use some of the string manipulation VB function such as Len, Right, Left, Mid, Trim, Ltrim, Rtrim, Ucase, Lcase, Instr, Val, Str ,Chr and Asc.

(i)The Len Function

The length function returns an integer value which is the length of a phrase or a sentence, including the empty spaces. The format is

Len (“Phrase”)

For example,

Len (VisualBasic) = 11 and Len (welcome to VB tutorial) = 22

The Len function can also return the number of digits or memory locations of a number that is stored in the computer. For example,

Private sub Form_Activate ( )

X=sqr (16)

Y=1234

Z#=10#

Print Len(x), Len(y), and Len (z)

End Sub

will produce the output 1, 4 , 8. The reason why the last value is 8 is because z# is a double precision number and so it is allocated more memory spaces.

(ii) The Right Function

The Right function extracts the right portion of a phrase. The format is

Right (“Phrase”, n)

Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted. For example,

Right(“Visual Basic”, 4) = asic

(iii)The Left Function

The Left$ function extract the left portion of a phrase. The format is

Left(“Phrase”, n)

Where n is the starting position from the left of the phase where the portion of the phrase is going to be extracted. For example,

Left (“Visual Basic”, 4) = Visu

(iv) The Ltrim Function

The Ltrim function trims the empty spaces of the left portion of the phrase. The format is

Ltrim(“Phrase”)

.For example,

Ltrim (“ Visual Basic”, 4)= Visual basic

(v) The Rtrim Function

The Rtrim function trims the empty spaces of the right portion of the phrase. The format is

Rtrim(“Phrase”)

.For example,

Rtrim (“Visual Basic ”, 4) = Visual basic

(vi) The Trim function

The Ttrim function trims the empty spaces on both side of the phrase. The format is

Trim(“Phrase”)

.For example,

Trim (“ Visual Basic ”) = Visual basic

(viii) The Mid Function

The Mid function extracts a substring from the original phrase or string. It takes the following format:

Mid(phrase, position, n)

Where position is the starting position of the phrase from which the extraction process will start and n is the number of characters to be extracted. For example,

Mid(“Visual Basic”, 3, 6) = ual Bas

(ix) The InStr function

The InStr function looks for a phrase that is embedded within the original phrase and returns the starting position of the embedded phrase. The format is

Instr (n, original phase, embedded phrase)

Where n is the position where the Instr function will begin to look for the embedded phrase. For example

Instr(1, “Visual Basic”,” Basic”)=8

(x) The Ucase and the Lcase functions

The Ucase function converts all the characters of a string to capital letters. On the other hand, the Lcase function converts all the characters of a string to small letters. For example,

Ucase(“Visual Basic”) =VISUAL BASiC

Lcase(“Visual Basic”) =visual basic

(xi) The Str and Val functions

The Str is the function that converts a number to a string while the Val function converts a string to a number. The two functions are important when we need to perform mathematical operations.

(xii) The Chr and the Asc functions

The Chr function returns the string that corresponds to an ASCII code while the Asc function converts an ASCII character or symbol to the corresponding ASCII code. ASCII stands for “American Standard Code for Information Interchange”. Altogether there are 255 ASCII codes and as many ASCII characters. Some of the characters may not be displayed as they may represent some actions such as the pressing of a key or produce a beep sound. The format of the Chr function is

Chr(charcode)

and the format of the Asc function is

Asc(Character)

The following are some examples:

Chr(65)=A, Chr(122)=z, Chr(37)=% , Asc(“B”)=66, Asc(“&”)=38



Sunday, March 14, 2010

Programming String Manipulation in C#

Trim Function

The trim function has three variations Trim, TrimStart and TrimEnd. The first example show how to use the Trim(). It strips all white spaces from both the start and end of the string.

//STRIPS WHITE SPACES FROM BOTH START + FINSIHE
string Name = " String Manipulation " ;
string NewName = Name.Trim();
//ADD BRACKET SO YOU CAN SEE TRIM HAS WORKED
MessageBox.Show("["+ NewName + "]");

TrimEnd

TrimEnd works in much the same way but u are stripping characters which you specify from the end of the string, the below example first strips the space then the n so the output is String Manipulatio.

//STRIPS CHRS FROM THE END OF THE STRING
string Name = " String Manipulation " ;
//SET OUT CHRS TO STRIP FROM END
char[] MyChar = {' ','n'};
string NewName = Name.TrimEnd(MyChar);
//ADD BRACKET SO YOU CAN SEE TRIM HAS WORKED
MessageBox.Show("["+ NewName + "]");

TrimStart

TrimStart is the same as TrimEnd apart from it does it to the start of the string.

//STRIPS CHRS FROM THE START OF THE STRING
string Name = " String Manipulation " ;
//SET OUT CHRS TO STRIP FROM END
char[] MyChar = {' ','S'};
string NewName = Name.TrimStart(MyChar);
//ADD BRACKET SO YOU CAN SEE TRIM HAS WORKED
MessageBox.Show("["+ NewName + "]");

Find String within string

This code shows how to search within a string for a sub string and either returns an index position of the start or a -1 which indicates the string has not been found.

string MainString = "String Manipulation";
string SearchString = "pul";
int FirstChr = MainString.IndexOf(SearchString);
//SHOWS START POSITION OF STRING
MessageBox.Show("Found at : " + FirstChr );

Replace string in string

Below is an example of replace a string within a string. It replaces the word Manipulatin with the correct spelling of Manipulation.

string MainString "String Manipulatin";
string CorrectString = MainString.Replace("Manipulatin", "Manipulation");
//SHOW CORRECT STRING
MessageBox.Show("Correct string is : " + CorrectString);

Strip specified number of characters from string

This example show how you can strip a number of characters from a specified starting point within the string. The first number is the starting point in the string and the second is the amount of chrs to strip.

string MainString = "S1111tring Manipulation";
string NewString = MainString.Remove(1,4);

//SHOW OUTPUT
MessageBox.Show(NewSring);

Split string with dilemeter

The example below shows how to split the string into seperate parts via a specified dilemeter. The results get put into the Split array and called back via Split[0].

string MainString = "String Manipulation";
string [] Split = MainString.Split(new Char [] {' '});
//SHOW RESULT
MessageBox.Show(Convert.ToString(Split[0]));
MessageBox.Show(Convert.ToString(Split[1]));

Thursday, December 20, 2007

8 Ways to Boost Your Career in '08

December 21, 2007 (Computerworld) Today's IT professionals are an evolving breed. The job keeps morphing as companies demand not just technical know-how, but more business acumen, analytical skills and industry knowledge as well.

Kudos if you've pulled that all together, but don't rest just yet. The evolution isn't over, as the upcoming year promises more changes. If you want to stay in the driver's seat of your own career, put these items on your to-do list:

1. Incorporate security into your responsibilities. Security and related disciplines, such as business continuity and disaster-recovery planning, are permeating all levels of the organization. That means all IT workers, and not just the security folks, will have to contribute by understanding how business processes, technical requirements and security intersect.

"Everyone has to understand security to a certain degree and apply it to their responsibilities," says Sam Helmich, vice president of technology at ADM Investor Services Inc. in Chicago. The learning requirements vary by IT positions, but Helmich recommends that you seek out security classes and certification. Finding mentors from the security team is another good way to prepare

2. Re-engineer processes. IT has always been responsible for keeping everything running and developing new systems, says Michael Cummins, CIO at the Georgia Institute of Technology's College of Management and a clinical professor of management, but now he sees a new responsibility emerging: re-engineering business processes and workflow.

"We've seen movement to business processes and workflow analysis as you try to show how systems can help re-engineer how you do the work and make it more efficient," Cummins says. "That's where we see all these big productivity gains."

To deliver this, you must understand how your business-side colleagues actually do their jobs, he says. You can start by signing up as a project lead, finding a business-side mentor or working as a systems analyst.

3. Use analytics to guide business decisions. "We're seeing more and more companies that are stellar examples of using data analysis to run their business," Cummins says. Casinos, for example, collect and analyze detailed data on individual players and then tailor their marketing based on those findings. Other industries are following suit, which means you'll have to set up the systems and understand what data to mine and analyze.

To brush up on analytics get onto projects that expose you to the needs and goals driving non-IT departments, study vendor information on how business intelligence applications can provide data to drive decisions, and get training in Six Sigma, a data-driven methodology for eliminating defects.

4. Be more versatile. There will always be a need for deep technical skills , but you'll be obsolete if all you can offer is one particular expertise, says Pamela Taylor, a solutions architect at a subsidiary of a Fortune 50 company and vice president of SHARE, an IBM user group.

"Keep yourself open to new approaches," Taylor says. "While there is some need for specialization and to demonstrate an expertise for the particular role you're in now, you must keep yourself aware of and consistently educated in new things that are emerging."

5. Work on multifunctional programs and multidisciplinary teams. Companies are putting together more teams of workers from diverse departments to deliver technology-related projects, says Diane Morello, an analyst at Gartner Inc. in Stamford, Conn. Getting assigned to those teams is a key to getting broad business knowledge and becoming known outside IT.

"Individuals are going to work much more consistently around multidisciplinary teams, and that means their competencies need to be understood and known by people outside their skill sets," Morello says.

In short, you must be skilled in teamwork, effective communication and change management. Try to work for managers who operate across business units. Or, if you can, get assigned to a boundary-spanning role, and seek some relief from daily operational duties so you can focus on the big picture.

6. Beef up your business skills. The need to do this has been building for a while, but 2008 will put an even greater emphasis on business acumen, says Kate M. Kaiser, an associate professor of IT at Marquette University and coordinator of the Society for Information Management study "The Information Technology Workforce: Trends and Implications 2005-2008."

The need for business knowledge is moving farther down the IT workforce chain, she says. Even newly minted IT workers will have to have business smarts. Moreover, companies are looking for IT workers who have expertise in functional areas, such as marketing or finance, says David Foote, CEO and chief research officer of research firm Foote Partners LLC in New Canaan, Conn.

Getting a degree in business management -- an MBA if you have a tech-related bachelor's degree, or a bachelor's in business if you have an associate's degree in technology -- can help prepare you for this new reality, Kaiser says. But so can on-the-job management experience, such as leading projects.

7. Be more accountable. The folks in finance, marketing, HR and other corporate departments already use data to evaluate performance. IT workers will increasingly have to do the same, Cummins says. Granted, evaluating an IT shop can be hard, because of the lack of productivity measures and because of the difficulty of measuring certain, sometimes intangible, gains. But be prepared to show your value.

Learn Six Sigma-type tools and benchmarking, and learn from business managers who have reputations for running efficient departments.

8. Manage your own career. You can't rely on your manager, company or vendors to determine a path for you, because those predetermined paths might be too narrow or even obsolete, Foote says. You yourself must prepare for tomorrow by evaluating your skills and filling in what's missing through certification, education and on-the job experience.

"This is the year you can no longer sleepwalk through your career," Morello adds. "Each person has to take ownership of his or her career path."