Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > Общие вопросы .NET
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 31.03.2010, 22:21   #1
ArniLand
Пользователь
 
Регистрация: 27.06.2009
Сообщений: 89
По умолчанию Проблема с циклом удаления символа

Нужно чтобы из строчки удалялся символ "а", но почему то у меня этот цикл игнорируется. Подскажите что не так.

Код программы:
Код:
//Row.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Row
    {

        public String dataRow;


        public Row(String str)
        {
            dataRow = str;
        }

        public string Zamena(String str)
        {
            StringBuilder sb = new StringBuilder(str);

            for (int j = 0; j < sb.Length; j++)
            {
                if (sb[j] == 'a')
                    sb[j] = ' ';
            }
            string corrected = sb.ToString();
            return corrected;
        }
    }
}

//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Vedite kolichestvo strochek: ");
            int countRow = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Vedite strochki: ");
            
            Text obgText = new Text(countRow);
            for (int i = 0; i < countRow; i++)
            {
                
                obgText.addRow(Console.ReadLine());
            }

            
            Console.WriteLine("----\n\n" + obgText.ToString() + "\n----\n");

            Console.WriteLine("Vedite nomer strochki dla ydalenia ");
            int numberOfRow = Convert.ToInt32(Console.ReadLine());
            if (numberOfRow < countRow)
            {
                
                obgText.remoweRow(numberOfRow - 1);
            }

            Console.WriteLine("----\n\n" + obgText.ToString() + "\n----\n");

            
            Console.WriteLine("Samaja dlinaja strochka v tekste: " + obgText.getMaxLenght());

           ;

            Console.WriteLine("Ochistka teksta.");
            
            obgText.removeAll();
            Console.WriteLine("----\n\n" + obgText.ToString() + "\n----\n");
        }
    }
}

//Text.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Text
    {
        
        private const int countRows = 100;
     
        private Row[] texts;
        
        private int amountRows;

        
        public Text(int amountRow)
        {
            amountRows = amountRow;
            texts = new Row[countRows];
            amountRows = 0;
        }

        
        public void addRow(string str)
        {
            texts[amountRows] = new Row(str);
            texts[amountRows].Zamena(str);
            amountRows++;
        }

       
        public void remoweRow(int numberRow)
        {
            for (int i = numberRow; i < (countRows - 1); i++)
            {
                texts[i] = texts[i + 1];
            }
            texts[countRows - 1] = null;
            amountRows--;
        }

      
        public void removeAll()
        {
            for (int i = 0; i < countRows; i++)
            {
                texts[i] = null;
            }
            amountRows = 0;
        }

        
        public string getMaxLenght()
        {
            string max = texts[0].dataRow;
            for (int i = 1; i < amountRows; i++)
            {
                if (texts[i].dataRow.Length > max.Length)
                {
                    max = texts[i].dataRow;
                }
            }

            return max;
        }
        
        public string ToString()
        {
            string str = "";
            for (int i = 0; i < amountRows; i++)
            {
                str = str + " " + texts[i].dataRow;
            }

            return str;
        }
    }
}
ArniLand вне форума Ответить с цитированием
Старый 31.03.2010, 23:16   #2
Cpluser
Форумчанин
 
Аватар для Cpluser
 
Регистрация: 16.02.2009
Сообщений: 555
По умолчанию

Метод
Код:
string a="ddewdwafewdwea";
a = a.Replace("a", "");
Cpluser вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Непонятная проблема с циклом RIO Общие вопросы Delphi 3 31.01.2010 23:29
Проблема с циклом, Паскаль Паскалька^^ Помощь студентам 2 10.12.2009 15:37
Проблема удаления папок и файлов NetSpace Софт 2 30.10.2009 13:13
Adodb+smarty проблема с циклом while Oleg_453 PHP 2 02.12.2008 14:41
Проблема с циклом.. POPOV Помощь студентам 3 29.04.2008 18:36