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

  • Home
  • SEARCH
  • 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 6803805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:23:21+00:00 2026-05-26T19:23:21+00:00

I am trying to come up with a method of extracting 4 characters that

  • 0

I am trying to come up with a method of extracting 4 characters that occur after a substring match in a string. The closest thing I could come up with is terribly inefficient looking and doesn’t even work all that well. Does anyone know a better way of doing this?

@echo off
cls
SET "_TMPVAR=Ports|http:8000|https:8443|"
SET _TMPVAR=%_TMPVAR:|=,%
FOR /F "tokens=1-3 delims=," %%m in ("%_TMPVAR%") do (
  SET "_TMPVAR1=%%n"
  SET "_TMPVAR2=%%o"
)
SET _HTTPS=0000
IF "%_TMPVAR1:~4,1%"=="s" (
  SET "_HTTPS=%_TMPVAR1:~-4%"
)
IF "%_TMPVAR2:~4,1%"=="s" (
  SET "_HTTPS=%_TMPVAR2:~-4%"
)
SET _
ECHO SSL Port is %_HTTPS%
pause
  • 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-05-26T19:23:21+00:00Added an answer on May 26, 2026 at 7:23 pm

    One way to improve it is to eliminate the seemingly unnecessary comma replacement:

    SET "_TMPVAR=Ports|http:8000|https:8443|"
    FOR /F "tokens=1-3 delims=|" %%m in ("%_TMPVAR%") do (
      SET "_TMPVAR1=%%n"
      SET "_TMPVAR2=%%o"
    )
    

    Further, you can take advantage of the delimiter list to split on | and : to break up your schemes and ports, allowing you to put the logic inside the FOR statement:

    @echo off
    cls
    SET "_TMPVAR=Ports|http:8000|https:8443|"
    SET _HTTPS=0000
    FOR /F "tokens=2-7 delims=|:" %%a in ("%_TMPVAR%") do (
        IF %%a==https SET _HTTPS=%%b
        IF %%c==https SET _HTTPS=%%d
        IF %%e==https SET _HTTPS=%%f
    )
    SET _
    ECHO SSL Port is %_HTTPS%
    

    An advantage of using the delimiter behavior is that it allows for port numbers of any length.

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

Sidebar

Related Questions

I've been trying to come up with a method, that given a day of
I'm trying come up with a method to determine how long after the user
I am trying to come up with a design for a method that takes
I am trying to come up with a method factory that looks inside config
I am trying to come up with a method that takes an integer and
I am trying to come up with a C# method that will be able
I'm trying to come up with a javascript/jquery method that will allow me to
I am trying to come up with a method to differentiate between form being
I'm trying to come up with a method which will measure and return the
I'm trying to come up with an algorithm that will do the following: If

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.