Computing.Net > Forums > Programming > how to remove a certain string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to remove a certain string

Reply to Message Icon

Name: fidodido
Date: December 26, 2007 at 14:01:14 Pacific
OS: Win XP
CPU/Ram: Duo core 2.8 / 1 GB ram
Product: Intel/Gega Byte
Comment:

i want to remove the \nul string from this line

"D:\Documents and Settings\fidodido\Desktop\New Folder3\asda\nul"

i tried to use

for /f "skip=1 tokens=* delims=nul" %%I in (text.txt) do echo %%I>>text2.txt

but i found that batch file takes nul as three delims which are n ,u & l and this causes me a problem , so if you could help me with this problem i will be so pleased

text:is the text file contaning the lines , also it is not only one line , they are many lines all ending with \nul"

text2:is my output text file

thanks in advance




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: December 26, 2007 at 14:37:45 Pacific
Reply:

@Echo Off > text2.txt
SetLocal EnableDelayedExpansion
For /F "tokens=* delims=" %%j in (text.txt) Do (
Set Row=%%j
Set Row=!Row:\nul=!
Echo.!Row!>> text2.txt)



0

Response Number 2
Name: fidodido
Date: December 26, 2007 at 14:48:07 Pacific
Reply:

thanks IVO it worked :)
but could you plz tell me what these lines mean

SetLocal EnableDelayedExpansion

Set Row=!Row:\nul=!

Echo.!Row!>> text2.txt

thanks in advance


0

Response Number 3
Name: IVO
Date: December 28, 2007 at 03:37:20 Pacific
Reply:

Your need (erase the \nul string) is just performed by

Set Row=!Row:\nul=!

that replaces the Row's substring \nul with the "nul" string.

As you see, the value of the environment variable Row is referred by coding !Row! instead of the usual %Row%.

Here Row is used as "Dynamic Variable", i.e. it is expanded at run time catching each line of the text file while the For loop goes on. Otherwise %Row% would just be empty as it would be freezed at its state at the beginning of the loop.

To enable dynamic variables the SetLocal statement must be coded and delayed expansion needs to be used any time environment variables have to be referred inside compound statements (embraced by ()).

To get a short and not friendly tutorial on the subject type Set /? at prompt.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: how to remove a certain string

How to replace a string using sed? www.computing.net/answers/programming/how-to-replace-a-string-using-sed/18003.html

How to convert a CAD file to .net www.computing.net/answers/programming/how-to-convert-a-cad-file-to-net/15097.html

How to clear a textbox in asp.net www.computing.net/answers/programming/how-to-clear-a-textbox-in-aspnet-/8234.html