Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Adding '\'s To A String Posted by stricks on 27 Jun 2005 at 6:03 AM
This message was edited by stricks at 2005-6-27 11:6:59

This message was edited by stricks at 2005-6-27 6:24:7

I have a String that consists of, "C:\My Stuff\Cool\ok.txt".

How can I first convert that into a string and then whenever there is a a '\' character, add another one?

Actually, I can convert, I think, I just need help with the '\'.

This is how I was trying to do it

	public static String addSlash(String file){
		
		char[] finshed_pathname, orginal_pathname;
		int length = file.length();
		
		orginal_pathname = new char[length];
		
		file.getChars(0,length,orginal_pathname, 0);
		System.out.println(length);
		
		// Get teh length for the finishedFile array
		for(int i = 0 ; i < orginal_pathname.length ; i++){
			if(orginal_pathname[i] == '\\'){
				length++;
			}
			System.out.print(orginal_pathname[i]);
		}
		System.out.println();
		System.out.println(length);
		
		
		finshed_pathname = new char[length];
		
		for(int i = 0, j=0 ; i < orginal_pathname.length ; i++){
			finshed_pathname[j] = orginal_pathname[i];
			System.out.print(finshed_pathname[j]);
			if(orginal_pathname[i] == '\\'){
				j++;
				finshed_pathname[j] = '\\';
				System.out.print(finshed_pathname[j]);
			}
			
		}
		System.out.println();
				
		file = new String(finshed_pathname);
		return file;
	}


Generates : \\\\\t...................................
BUT, the out.prints in the for loop creates this:
C:\\Documents and Settings\\stricbr3\\Desktop\\Info\\Q&A.txt

What am I doing wrong?


Thanks




Thread Tree
stricks Adding '\'s To A String on 27 Jun 2005 at 6:03 AM
NCS_One Re: Adding '\'s To A String on 27 Jun 2005 at 11:29 AM
stricks Re: Adding '\'s To A String on 27 Jun 2005 at 12:58 PM
Vilanye Re: Adding '\'s To A String on 27 Jun 2005 at 4:28 PM
SnookerLoopy Re: Adding '\'s To A String on 5 Jul 2005 at 8:30 PM
Liree Re: Adding '\'s To A String on 9 Jul 2005 at 7:36 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.