الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كود لحذف الحواشي من النص

بدأه لؤلؤه مضيئه في 14 فبراير 2012 · 3 رد · 566 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

ارجو المساعده في حل مشكلةكود لحذف فوت نوت من ملف نصي يبدا ب ستار وينتهي بترقيم الصفحه بين قوسين كما في الشكل(1) حيث لا يظهر اي نتيجه

والكود كالتالي

private void cleanActionPerformed(java.awt.event.ActionEvent evt) {                                      
String s;

            try {
                BufferedReader buf=new BufferedReader(new FileReader(c)); 
                s= buf.readLine();

        ArrayList  list=new ArrayList();
            list.add(s);
        while(!list.contains(null) ) {

        if(list.contains('*')){
        while(!list.contains('(')) {

                 list.clear();
                 s= buf.readLine();
        list.add(s);

        }
        }
        s= buf.readLine();
        list.add(s);

        }



           area.setText(list.toString()); 


    } catch (IOException ex) {
                Logger.getLogger(Files.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

تم تعديل هذه المشاركة بواسطة لؤلؤه مضيئه في 14 فبراير 2012 في 11:48

#2

غير واضح السؤال ولا يوجد شكل ،

وضح المدخل بمثال والمخرج المطلوب ..

بالتوفيق،

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#3

البرنامج يعمل كذا تاسك منها فتح ملف نصي وقراءته وتنضيف نص الملف من الحواشي هي اللتي تاتي في نهاية النصوص

و اما ان تبدا بلاين او نجمه وبعدها نص

والمطلوب حذف الحاشيه اي النجمه ومابعده من نص او لاين ومابعده من نص

والكود الموضح اعلي يقوم بتعبئة البفر بنص الملف ثم ونسخ هذا النص في سترينق بفر اخر بدون الحاشيه لنحصل ع نص خالي من الحواشي

تم تعديل هذه المشاركة بواسطة لؤلؤه مضيئه في 18 فبراير 2012 في 08:41

#4

يمكنكم قرائه النص في الstring ثم تطبيق عملية الازالة بدلاً من تطبيقها بعد كل سطر .. الا اذا كان هناك غرض ما ،،

استخدم الدالة replaceAll في الString ومرر له نمط الازالة ، مثال:

System.out.println("Filtered Text: " + text.replaceAll("\\*.*[(\\d*)]", ""));

مثال:

import java.io.File;
import java.io.IOException;

import java.util.Scanner;

public class FilterText {
	public static void main(String[] args) {

		try {
			String text = getFileContent("a.txt");
			System.out.println("Original Text: " + text);
			System.out.println("\n\n");
			System.out.println("Filtered Text: " + text.replaceAll("\\*.*[(\\d*)]", ""));
		}
		catch(IOException e) {
			System.err.println("Cannot Reading the file");
		}
	}

	private static String getFileContent(final String path) throws IOException {
		Scanner input = new Scanner(new File(path));
		StringBuilder text = new StringBuilder();

		while (input.hasNext() ) {
			text.append(input.nextLine());
			text.append("\n");
		}

		return text.toString();
	}
}

output:

C:\>java FilterText
Original Text: This is the file content, here you will find a notes that you
 should remove it *this is small notes(2)
the best solution is to use regular expression and define the pattern 
you want to remove * this also another note to remove(5) good luck!
the last testing statement *akjdas (630) bye
Filtered Text: This is the file content, here you will find a notes that you
 should remove it
the best solution is to use regular expression and define the pattern 
you want to remove  good luck! 
the last testing statement  bye

للمزيد:

http://docs.oracle.com/javase/tutorial/essential/regex/index.html

بالتوفيق،

تم تعديل هذه المشاركة بواسطة Wajdy Essam في 19 فبراير 2012 في 23:06

1

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

مواضيع مشابهة