Google
 

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, February 5, 2009

Full Text Catalogs in SQL Server

Gathering status and detail information for all Full Text Catalogs for an instance of SQL Server


Problem
I have several Full Text Search enabled databases and these databases contain several catalogs. Very often, I deploy these databases to many servers, so I need to know if these are deployed correctly and also find out as quickly as possible. I need to know the population progress as well, but using management studio is too slow and also very hard to find out how much the catalogs have been populated.

Solution
You can use a T-SQL Script to pull all the major information at once. The query below has been tested and works on SQL 2000, SQL 2005 and SQL 2008.

Tuesday, February 19, 2008

Sharing Session State between ASP and ASP.NET

Sharing Session State between ASP and ASP.NET

by Sidney Forcier

Despite all of Microsoft's best efforts to make ASP and ASP.NET coexist effortlessly, one area remains a stumbling block... session state. Fortunately the advantages of ASP.NET's upgraded session state management far outweigh the inconvenience of not being able to pass "Classic" session information to .NET. Unfortunately there is no simple solution; the most I can offer is an easy to implement workaround.

In trying to find a suitable resolution, I've come across two good options that are worth mentioning. The first involves parsing the session information out to hidden form fields on a "Classic" intermediate page and then submitting the page to a .NET intermediate page that loads the form fields into the session state. This is a good, simple solution, however it doesn't work both ways. In .NET you cannot specify the page that you submit to. Each page has to PostBack to itself.

The second option is probably closer to an actual solution than to a workaround. Billy Yuen at Microsoft has developed an effective solution. The code is elegant, the integration appears to be seamless, but I couldn't get it to work on my system (remember I said that there was no simple solution, not that there was no solution at all). If this solution works for you, great! You won't need my code and you'll be happily passing session information from "Classic" to .NET like it's going out of vogue, thanks for stopping by.

Ok, if you're still reading let me briefly describe the workaround I've created. It requires a database, but it is not important which type of database (though the code is written for SQL Server). When a page (source page) wants to redirect to another page (destination page) that uses a different version of ASP, it calls an intermediate page. The source intermediate page takes each session variable and adds it to the database along with a Globally Unique ID (GUID). Since "Classic" and .NET use different SessionID formats it is not possible to use SessionID, hence the use of a GUID. The source intermediate page then passes the GUID to the destination intermediate page through a Querystring variable. The destination intermediate page retrieves the session information from the database, cleans up after itself, and then redirects to the destination page. It's similar to the first workaround, but supports transferring state in both directions.

Code Usage

Installation

  1. Run the SQL Query in "ASPSessionState.sql" on the database which will hold the temporary Session information.
  2. Copy the .asp and .aspx.* (SessionTransfer.aspx and SessionTransfer.aspx.cs) files to a folder on your website.
  3. Update connection object information in the "SessionTransfer.asp" and "SessionTransfer.aspx.cs" files. It is located in three places in each file (sorry about not consolidating the connection info).
  4. Compile the aspx files.
  5. The .asp and .aspx.* files must all reside in the same folder to work.

Usage

For use in a Hyperlink (Anchor Tag) or a Response.Redirect, set the destination URL to be one of the following:

From a ASP "Classic" page:

 SessionTransfer.asp?dir=2aspx&url=

From an ASP.NET page:

 SessionTransfer.aspx?dir=2asp&url=

The code will transfer the Session information and Redirect the user to the url specified by or .

Download

You can download the code from here: session_transfer.zip (4.6 KB).

Thursday, January 10, 2008

Are Google Results Hazardous To Your Health?

Pharmaceutical types think so

First thing's first: I'm suspicious of the pharmaceutical industry in general. A lot of people are, but as a journalist, suspicion is part of the job. Also, I have the researcher's tendency toward cyberchondriasis, so take my non-medical expertise for what it's worth.

Which isn't much. I put that out there so others won't have to.

I also make that disclaimer in advance of what is a grander, more important topic: To what extent is the so-called "Googlization of reality" affecting our understanding of the world around us? The answer may not be so available and everybody with a stake in it will give you different answers.

If you took the Internet's word for everything, you might believe that Ron Paul is a Republican frontrunner or that the elephant population has tripled in the past six months (see Stephen Colbert's "wikiality" social experiment).

Clearly, information on the Internet (even Google) isn't perfect, and knowing your source is paramount, hence my opening disclaimer.

The Center for Medicine in the Public Interest (CMPI) is a medical industry thinktank, fronted by former Bush Administration FDA officials. CMPI released a study this week outlining the perils of relying on Google for prescription medication information.

“What we found was not only disturbing, but dangerous to public health,” said CMPI vice president Robert Goldberg. “For millions of Americans, Google has replaced the family physician. People trust, and make decisions, based on the information they find online. With few exceptions, the information we found appeared legitimate but had no medical authority whatsoever. In many cases, we found lawyers posing as medical experts.”

For searches on keywords like "Crestor side effects" and "Avandia side effects" CMPI found:

  • 65% of the first three pages of search results came from sites which were biased or contained unverified information.
  • Almost half of the first three pages of search results belonged to lawyers and attorney referral services seeking plaintiffs for class action lawsuits.
  • Zero official regulatory pages or professional medical organizations appeared in the inventory of results.

Crestor is a cholesterol medication made by AstraZeneca and Avandia is a type 2 diabetes drug produced by GlaxoSmithKline.

Many of the results also referred to "unmoderated" patient forums, sites selling or promoting "alternative medicines" or were sites run by, as CMPI describes them, "anti-pharmaceutical activists."

All of these concerns and findings are published in a 33-page paper entitled "Insta-Americans: The Empowered (and Imperiled) Health Care Consumer in the Age of Internet Medicine." Similar concerns were voiced about selective serotonin reuptake inhibitors and their (Internet) relationship to teen suicide rates and links between vaccinations and autism.

"Much like our email boxes are filled by 'spam' urging us to collect millions from Nigeria or confirm our banking information from phony Ebay or Bank of America security sites, a lot of the medical 'information' on the Web is designed to sell, deceive or frighten, rather than inform," said Goldberg.

Citing a Pew report, CMPI 113 million Americans search for health information, but three quarters rarely check the sources of the information.

According to Peter Pitts, CMPI President and former Associate Commissioner for External Affairs for the FDA, "it is important to remember that not everything online is true. The Internet has made it easier than ever before for charlatans and quacks to spread fear and misinformation. Mark Twain wrote: ―'Beware of health books. You might die of a misprint.' The same can now be said of the Web."

And that can really affect pharmaceutical sales. Because doctors were afraid of lawsuits and patients were afraid of, you know, death, Avandia prescriptions had declined by 60 percent as September 2007.

Of course, it could also have something to do with the black box warning the FDA put on Avandia about increased heart problems. If you use a less targeted keyword, like simply "avandia," you'll find that official government warning (and one for Crestor, too), along with official pharmaceutical company pages, scores of lawyer-sponsored AdWords links, pages from WebMD, the Mayo Clinic, the New York Times, USA Today, and a group called Public Citizen which runs a site called WorstPills.org.

Pitts and Goldberg aren't especially fond of that last group, and single out Dr. Sidney Wolfe, who runs the site, as a source of misinformation about Avandia. Wolfe joins several others with lots of letters behind their names on the site's About page. Maybe it's because Wolfe has a close relationship with Ralph Nader, that CMPI labels them an anti-pharmaceutical activist group. Who knows?

But Wolfe's opinion of Avandia match a Cleveland Clinic doctor named Stephen Nissen, whose May 2007 New England Journal of Medicine article about the drug CMPI cites as a "common source of misinformation." Dr. Nissen's viewpoint however is echoed by a Toronto endocrinologist in this more recent (December 2007) USA Today article.

So why fixate on these drugs in particular? You could present a number of theories. CMPI is partially funded by the pharmaceutical industry, the Lilly Endowment (connected to Eli Lilly) being one of the largest contributors. Patients shying away from pharmaceuticals is bad for business.

A clue could be in reporter Evelyn Pringle's article about Avandia, the FDA and CMPI. Pringle labels CMPI as "a home for industry hit men who served in the Bush Administration's FDA." Pringle explains in detail Pitts' and Goldberg's association with Manning, Selvege & Lee, a PR firm representing many pharmaceutical companies, including AstraZeneca, and with FDA spokesman Douglas Arbesfeld, who has a close relationship with GSK.

But I'm sure that has nothing to do with their opinion on what is misinformation and what isn't.

The extra-cynical of us might also notice CMPI's definite stance against regulation of the health care industry and any type of universal health care. Those cynics might get really crazy and suggest that by advocating a greater reliance on your doctor and the drugs he or she prescribes rather than moonbat alternatives cuts down on the perception that there are flaws in the health care industry in its current privatized state. Plus, with obesity rates the way they are, diabetes medicines are big, big money.

But that's just crazy right?

Well, anyway, CMPI says to check your sources, especially those sources found on Google, the nation's most popular search engine, where most online health research begins. Sometimes people manipulate the information to suit them.

But you might also conclude that a variety of sources is a good thing. I could be wrong. After all, I did all my research for this article on Google.

Wednesday, December 26, 2007

8 Tips for Landing a Job in 2008

1. Come prepared for the interview. This sounds like a no-brainer, but hiring managers are increasingly looking for candidates who can do more than a "tech interview."

They may ask you to explain your past experiences or how you would handle certain situations on the job, says Jill Herrin, CEO of JDResources, Inc., a Memphis-based recruiter. These and other inquiries help employers to determine your communications skills as well as your technical knowledge.

2. Talk business. Prospective employers also want to know whether you understand how systems and applications affect various business divisions, Herrin says. "Technical interviews are still an important component to an interview process, but rarely are they the only determining factor anymore," he explains.

"We want somebody with technical acumen but I would like to know that these people know the basis for making money," says Frank Hood, CIO at Quiznos in Denver.

3. Work your relationships. Employers and job candidates alike are jumping on the use of social networks such as LinkedIn and Facebook to connect with college alumni, former business associates and mentors "to get better access to the inside jobs," says Dan Reynolds, CEO of Princeton, N.J.-based staffing firm The Brokers Group LLC.

You should too.

And if you're an entry-level candidate, social networks are a great way for you to get a foot in the door, says Michael Nieset, managing partner for Heidrick & Struggles' technology practice in Cleveland. You can identify and connect with potential employers through entry-level job listings on social networks.

4. Dot your "i"s. Make sure your resume and project accomplishments are clearly documented using proper English and correct spelling.

"You won't even make it past the first gate" if your resume' is sloppy, says Robert Rosen, immediate past president of SHARE and CIO at the National Institute of Arthritis and Musculoskeletal and Skin Diseases in Bethesda, Md.

5. Strut your stuff. Effective resumes are direct and succinct. Hiring managers want to see what you've achieved. "Employers want to see 'I managed this, I coordinated that'," says Reynolds. "They don't want to see 'assisted with this' or 'supported that.'" I

f you weren't the project leader on a particular effort, underscore what you did contribute. If you're a systems administrator, point out the importance of your role in a critical project and whether the effort was delivered under budget or ahead of schedule, says Katherine Spencer Lee, executive director at Robert Half Technology in Menlo Park, Calif.

6. Keep learning. Employers want IT workers who have a demonstrated thirst for knowledge and a willingness to learn new things. Pick up certifications in hot technologies or take an evening course at a local community college to improve your business acumen.

Then flaunt it. "Education is absolutely vital to further your career in IT," says Neill Hopkins, vice president of skills development at the Computing Technology Industry Association Inc. in Oakbrook Terrace, Ill.

7. Do what it takes to appear employable. If you're currently unemployed and seeking a full-time position, find a temporary position or work as a contractor, says Joel Reiter, an application analyst at U.S. Bancorp in St. Paul, Minn. It's "a good way of erasing a period of time where you didn't have a job." he says.

It's also important to demonstrate determination and flexibility, says Joe Trentacosta, CIO at the Southern Maryland Electric Cooperative in Hughesville. "Programmers need to be willing to step out of their comfort zone and learn new technologies, to work nights and weekends if necessary," he says. "It shows that they're willing to be aggressive and to learn new technologies."

8. Get a foot in the door. Don't hesitate to take a temporary position, a contract or a temp-to-hire job. As demand for IT workers has ticked up, rates for contractors are also on the rise, having jumped 3% to 5% over the past five months for IT contractors in general and by 10% to 15% for people with highly sought skills such as J2ee and open source programming abilities, says Reynolds.

"Once you come in as a temp or a contractor, no one is really looking at your resume. They're looking at whether you can or can't do a particular job," says Reiter.

IBM dishes five predictions for the future

IBM's last installment of its annual 'Next Five in Five' list looks forward to intelligent traffic systems and energy grids, more organic food, and better technology for doctors


Drained by your commute? Blood-sucking utility bills got you down? Wondering if that tomato in your dinner salad was really organic?

The cures to those ills and more may arrive within five years, according to IBM.

The company recently released its second annual set of "Next Five in Five" predictions, visions that sketch out a future where driving is a relative pleasure, eco-friendly devices save you money, and super doctors use advanced technology to probe your body's innermost depths in search of disease.

IBM's contention that driving will become safer and less aggravating may be particularly tantalizing for many.

The company said that during the next five years, a "wave of connectivity" between vehicles and roadways will help keep traffic flowing smoothly, drive down pollution, and get you to your destination easier, "without the stress."

This will be accomplished through "intelligent" traffic systems that automatically adjust light patterns and shift traffic to alternative routes, as well as cars that exhibit "reflexes" thanks to communication with other vehicles and roadside sensors, according to IBM.

The company's crystal ball also revealed that the long-simmering trend toward "smart energy" devices will proliferate wildly. "Dishwashers, air conditioners, house lights, and more will be connected directly to a 'smart' electric grid, making it possible to turn them on and off using your cell phone or any Web browser," a company statement asserts.

Even the act of eating will take on new meaning, in IBM's view: "You will know everything from the climate and soil the food was grown in, to the pesticides and pollution it was exposed to, to the energy consumed to create the product, to the temperature and air quality of the shipping containers it traveled through on the way to your dinner table."

The report also suggests that doctors' ability to heal us will become even more astounding. Due to advances in X-ray and audio technologies, doctors will gain "superpowers," according to IBM. Computers will also be able to compare your health data to an ocean's worth of other patient records, helping with diagnosis and treatment, the company said.

In addition, the company said cell phones will continue to grow in power and functionality. For example, phones will enable users to snap a photo of an article of clothing, pull in results from the Web about the brand and where to buy it, and then render the garment on top of a 3-D image of the user, IBM said.

IBM's list received a measured nod from Edward Cornish, editor of The Futurist magazine and past president of the World Future Society, an organization based in Bethesda, Maryland.

"Basically, the five forecasts seem to me to be quite reasonable," Cornish said. "They're based on technologies that have been around for a number of years and are simply extrapolations."

The Futurist has released its own list of predictions for 2008 and beyond.

The organization contends, among other things, that the world will have a billion millionaires by 2025; the earth is on the verge of a "significant extinction event;" and "nonhuman entities," such as robots fueled by artificial intelligence, will make more decisions.



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."