Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8297505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:26:30+00:00 2026-06-08T15:26:30+00:00

I’m trying to remove an asterisk from an environmental variable string, but can’t seem

  • 0

I’m trying to remove an asterisk from an environmental variable string, but can’t seem to do it.

I’m creating an m3u file based around search strings, so for instance I if I want to make an m3u file containing every song with the word love in it, I would enter:

m3u *Love*

And m3u.bat would create the file:

xLovex.m3u

But the regular method of replacing characters does not work with an asterisk. (Though I don’t have that problem with the question mark.)

set nam=%nam:*=x%.m3u

Instead creates the filename

x.m3u
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:26:31+00:00Added an answer on June 8, 2026 at 3:26 pm

    The easy answer is no.

    The problem that you’re encountering stems from the fact that the asterisk * is a special character when used with the SET search and replace method. It matches multiple characters in a limited, but still useful, way. You can learn about that here.

    The hard answer is Yes!

    I will provide you with two solutions. One an incomplete solution but elegent,
    the other complete and inelegent.

    Both methods will search for * and replace it with an x.
    Both methods will both search and modify the following string:

    *love*
    

    The first method that comes to mind is using a ‘FOR /L’ statement, and requires that you know how many characters long the environmental variable is.

    ::Major Edit::

    I thought I knew the various maximum size strings of environmental variables, but dbenham has taken me to school, shown me a kick-in-the-behind length function, and in the mean time completely reversed my opinions of the two solutions I’m presenting.

    Other than for the Windows 95/98/ME limitation of a 256 Character maximum environmental variable size. It seems that all versions of Windows using CMD.EXE have a limitation of 8,192 characters, well below what the documentation suggests.

    Both versions require delayed environmental variable expansion, but for two different reasons. One because I’m operating inside a FOR statement. The other because you cannot put a % pair inside another % pair because the command processor matches the second % that it encounters to the first one it encounters, but we need to use a variable inside another variable expression. (You’ll see.)

    This solution uses the strLen function (in line 3) from DosTips.com that can be found Here. Just slap it into a file called strLen.bat and be amazed at it’s speed!

    Solution 1: (FOR /L Solution) :: Preferred Solution ::

    setlocal ENABLEDELAYEDEXPANSION
    set nam=*love*
    rem calling strLen
    call :strLen nam len
    for /l %%x in (0,1,%len%) do if not "!nam:~%%x,1!"=="" if "!nam:~%%x,1!"=="*" (
        set /a plusone=%%x+1
        for /l %%y in (!plusone!, 1, !plusone!) do (
            set nam=!nam:~0,%%x!x!nam:~%%y!
        )
    )
    echo %nam%
    ENDLOCAL
    

    I think this is a quick and elegant solution It could be sped up by adding the contents of strLen.bat to the routine, but I wanted no confusion as to the author.

    If you, for some reason, do not wish to use strLen, then the next quickest method would probably use a GOTO loop.

    Solution 2: (Goto Solution)

    setlocal ENABLEDELAYEDEXPANSION
    set nam=*love*
    set num=0
    
    :loop
        set /a plusone=%num%+1
        if "!nam:~%num%,1!"=="*" set nam=!nam:~0,%num%!x!nam:~%plusone%!
        set /a num=%num%+1
    if not "!nam:~%num%,1!"=="" goto :loop
    
    echo %nam%
    EndLocal
    

    Special thanks to dbenham for pointing out the strLen function. It works faster than any batch based function has a right to!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.