Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2005, 07:45 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# String Performance Issues

Hi mates!

I am developing a C# Software that reads text files, each text file consists of anywhere between 100 ' s to 10,00,000 ' s of lines. I did the stupid mistake of using string to concat the lines one by one after having parsed through each line and concat it to a string. I have corrected this mistake by employing StringBuilder in my software.

However I am faced with another problem.

Each line has to be tokenized and each token needs to be checked and arranged into an INSERT command in SQL. Now comes the problem, it is costing too much in terms of performance, I end up with an array of type string of the size

number of tokens x number of lines

What would be the best solution for this?

I am enclosing some code here:

Code:
            String[] value;

            //Keep Reading until no more lines are found
            while (line != null)
            {
                //Get All field values for this line
                value = fileReader.tokenizeTopString(line);    

                //Append Value to The SQL String
                sSQL.Append(" INSERT INTO t_");
                sSQL.Append(tableNameTextBox.Text);
                sSQL.Append(" (");
                sSQL.Append(propertyStr);
                sSQL.Append(") VALUES (");

                for (int i = 0; i < value.Length; i++)
                {
                    if (value[i] == this.replaceTextBox[i].Text)
                        value[i] = this.replaceByTextBox[i].Text;

                 
                    if (i <= (value.Length - 2))
                    {
                        sSQL.Append(" '");
                        sSQL.Append(value[i]);
                        sSQL.Append("' ,");
                    }
                    else
                    {
                        sSQL.Append(" '");
                        sSQL.Append(value[i]);
                        sSQL.Append("' ");
                    }
                }

       sSQL.Append(");");
The FileReader class of my application consists of a method called tokenizeTopString which is as follows:

Code:
public String[] tokenizeTopString( String txt)
        {
            totalFields = 0;
            String[] values = txt.Split(seps);
            totalFields = values.Length;

            return values;
}
Cheers,
Muzz
 
Old December 20th, 2005, 11:39 AM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<center>Waiting For Reply!</center>






Similar Threads
Thread Thread Starter Forum Replies Last Post
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Performance in String concatenation rushman XSLT 4 September 27th, 2007 11:02 AM
Parse String Issues jafuller Javascript How-To 3 January 18th, 2007 04:01 PM
ADVICE WANTED: Website Performance Issues kwilliams Classic ASP Professional 2 December 19th, 2005 04:13 PM
ASP.NET controls performance issues Dmitriy Pro VB 6 0 November 1st, 2004 02:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.