Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
QuestionString manipulation with large strings [modified] Pin
Harvey Saayman8-Apr-09 22:17
Harvey Saayman8-Apr-09 22:17 
AnswerRe: String manipulation with large strings Pin
Rob Philpott8-Apr-09 22:52
Rob Philpott8-Apr-09 22:52 
GeneralRe: String manipulation with large strings Pin
Harvey Saayman8-Apr-09 23:13
Harvey Saayman8-Apr-09 23:13 
GeneralRe: String manipulation with large strings Pin
Rob Philpott8-Apr-09 23:24
Rob Philpott8-Apr-09 23:24 
GeneralRe: String manipulation with large strings Pin
Harvey Saayman8-Apr-09 23:38
Harvey Saayman8-Apr-09 23:38 
GeneralRe: String manipulation with large strings Pin
dojohansen8-Apr-09 23:58
dojohansen8-Apr-09 23:58 
GeneralRe: String manipulation with large strings Pin
Harvey Saayman9-Apr-09 0:30
Harvey Saayman9-Apr-09 0:30 
GeneralRe: String manipulation with large strings Pin
dojohansen9-Apr-09 1:14
dojohansen9-Apr-09 1:14 
But... when you call ToString().SubString() you are of course using string again.

The fact that the UI thread becomes active is probably no indication of the state of your program. Visual Studio need not hang in order for your program to be busy.

However, doing this a single time on a string of size on the order of thirty thousand characters should not take long at all.

I wrote a simple console app to test and with a string of 30000 characters and taking 28000 of them for the substring it takes about 0.01 seconds on my (cheapass) machine.

class Program
{
    static void Main(string[] args)
    {
        int size = 30000;
        int take = 28000;

        char[] chars = new char[size];
        for (int i = 0; i < size; i++) chars[i] = '.';
        
        string s = new String(chars);
        Stopwatch w = Stopwatch.StartNew();
        s = s.Substring(0, take);
        Console.WriteLine(w.Elapsed);
        Console.ReadKey(true);
    }
}


I'm at a complete loss as to how this can happen. Nor can I reproduce the problem you're having. So it seems like it might be time to reinstall your system... or at least try to take the code to another computer and compile it there and see if you still have the problem.

Should all this fail, you can always attempt using a char[] instead and implement "substring" yourself; after all it's a simple matter.

void substring(char[] src, char[] dest, int startIndex, int count)
{
   for (int i=0; i < count; i++)
     dest[i] = src[i + startIndex];
}


Obviously you should add range checking to that if you want it proper.
GeneralRe: String manipulation with large strings Pin
dojohansen9-Apr-09 1:25
dojohansen9-Apr-09 1:25 
JokeRe: String manipulation with large strings Pin
dojohansen9-Apr-09 1:37
dojohansen9-Apr-09 1:37 
Questionhow to select the text from the dropdownlist Pin
mdazeemuddin8-Apr-09 22:03
mdazeemuddin8-Apr-09 22:03 
QuestionPenel in Status Bar [modified] Pin
Sajjad Leo8-Apr-09 21:16
Sajjad Leo8-Apr-09 21:16 
AnswerRe: Penel in Status Bar Pin
DaveyM698-Apr-09 22:09
professionalDaveyM698-Apr-09 22:09 
GeneralRe: Penel in Status Bar Pin
Sajjad Leo8-Apr-09 23:19
Sajjad Leo8-Apr-09 23:19 
GeneralRe: Penel in Status Bar Pin
DaveyM699-Apr-09 0:11
professionalDaveyM699-Apr-09 0:11 
GeneralRe: Penel in Status Bar Pin
Sajjad Leo12-Apr-09 20:28
Sajjad Leo12-Apr-09 20:28 
QuestionMedia player control Pin
yesu prakash8-Apr-09 20:44
yesu prakash8-Apr-09 20:44 
AnswerRe: Media player control Pin
12Code8-Apr-09 20:52
12Code8-Apr-09 20:52 
QuestionHelp to me to find simple method for days of month Pin
M Riaz Bashir8-Apr-09 20:30
M Riaz Bashir8-Apr-09 20:30 
AnswerRe: Help to me to find simple method for days of month Pin
DaveyM698-Apr-09 20:37
professionalDaveyM698-Apr-09 20:37 
GeneralRe: Help to me to find simple method for days of month Pin
M Riaz Bashir8-Apr-09 20:39
M Riaz Bashir8-Apr-09 20:39 
QuestionOracle.DataAccess.Client - DbProviderFactories.GetFactory [modified] Pin
devvvy8-Apr-09 20:25
devvvy8-Apr-09 20:25 
AnswerRe: Oracle.DataAccess.Client - DbProviderFactories.GetFactory Pin
devvvy9-Apr-09 16:00
devvvy9-Apr-09 16:00 
Questionproblem with SetSystemTime() fucntion of Kernel32.dll Pin
cppwxwidgetsss8-Apr-09 19:34
cppwxwidgetsss8-Apr-09 19:34 
AnswerRe: problem with SetSystemTime() fucntion of Kernel32.dll Pin
dojohansen9-Apr-09 1:45
dojohansen9-Apr-09 1:45 

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.