Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Save first and last character of computername

Featured Replies

Hey guys,

I need your help.

I have to create a batch-file that saves the first and the last character of the %computername% in a variable.

I hope anyone can help.

Thanks ;)

I guess you could use the left string / right string batch equivalents.

set VAR=%COMPUTERNAME:~0,1%%COMPUTERNAME:~-1%

echo %VAR%

  • Author

Hi MrJinje,

soooo easy... B)

thank you, it works fine.

Edited by HØLLØW

  • Author

I've got another little question:

Is it possible to change upper-case letters to lower-case letters via batch?

Thank you

Yes it is; however the solution could be relatively simple or particularly awkward depending upon what you are specifically working with.

Could you pease provide more information with specifics regarding the data you are wishing to convert.

A "plain" batch "Capitalize" routine is here:

http://web.archive.org/web/*/http://www.fp...q.faqid+262.htm

(Wayback machine seems like having some problems right now :()

Here is a simplified version:

@ECHO OFF
SET String_in=%1
CALL :Capitalize %String_in%
SET String_out
GOTO :EOF

:Capitalize
:: Capitalize
:: This routine has been published by Frank-Peter Schultze
:: [url="http://www.fpschultze.de/smartfaq+faq.faqid+262.htm"]http://www.fpschultze.de/smartfaq+faq.faqid+262.htm[/url]
:: and slightly simplified by me

Set s=%1

For %%A In (
aA bB cC dD eE fF gG hH iI
jJ kK lL mM nN oO pP qQ rR
sS tT uU vV wW xX yY zZ
) Do Call :UCase %%A

SET String_out=%s%
GOTO :EOF

:UCase
Set _=%1
Call Set s=%%s:%_:~0,1%=%_:~1,1%%%
Goto :EOF

(no spaces)

jaclaz

I'd offer a similar generic routine, which allows for a user provided switch for conversion to Upper or Lower case.

chg_case.cmd

@ECHO OFF&SETLOCAL
IF %1' EQU ' GOTO :EOF
SET VAR=%*
FOR %%# IN (/ -) DO IF %VAR:~,1% EQU %%# (FOR %%$ IN (
U L) DO IF /I %VAR:~1,1% EQU %%$ (SET "YC=%%$"&&(
CALL SET VAR=%%VAR:%VAR:~0,3%=%%)))
IF NOT DEFINED YC (SET YC=L)
SET "LC_=abcdefghijklmnopqrstuvwxyz"
SET "UC_=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
FOR /L %%? IN (0,1,25) DO CALL :CC %%LC_:~%%?,1%% %%UC_:~%%?,1%%
ECHO=[%VAR%]
GOTO :EOF
:CC
IF /I %YC% NEQ U (CALL SET "VAR=%%VAR:%2=%1%%") ELSE (
CALL SET "VAR=%%VAR:%1=%2%%")

This allows you to pass your string to be converted to the script following your choice of case. If a choice of case isn't provided then all to lower case will be the default.

E.g. String To convert: TeSt StRinG = "I'm A StaR!"

Microsoft Windows [Version 6.0.6002]

Copyright © 2006 Microsoft Corporation. All rights reserved.

C:\Users\Yzöwl>Desktop\chg_case.cmd TeSt StRinG = "I'm A StaR!"

[test string = "i'm a star!"]

C:\Users\Yzöwl>Desktop\chg_case.cmd /u TeSt StRinG = "I'm A StaR!"

[TEST STRING = "I'M A STAR!"]

C:\Users\Yzöwl>Desktop\chg_case.cmd /l TeSt StRinG = "I'm A StaR!"

[test string = "i'm a star!"]

C:\Users\Yzöwl>Desktop\chg_case.cmd -u TeSt StRinG = "I'm A StaR!"

[TEST STRING = "I'M A STAR!"]

C:\Users\Yzöwl>Desktop\chg_case.cmd -l TeSt StRinG = "I'm A StaR!"

[test string = "i'm a star!"]

C:\Users\Yzöwl>

You can see that your choice of case can be applied using a forward slash or a hyphen and can itself be upper or lower case. You may also note that you are not required to enclose your string in double-quotes.

Now I know you did not ask for a VBS Script, but here is what you ask for done as a VBS script.

Save as a vbs script

Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Cn :Cn = Act.ExpandEnvironmentStrings("%ComputerName%")

MsgBox "Demo Upper Case " & UCase(Left(Cn,1) & Right(Cn,1)) & vbCrLf & _
"Demo Lower Case " & LCase(Left(Cn,1) & Right(Cn,1)),4128,"String Manipulation Demo"

  • Author

Hi there,

I'm searching for a solution to convert my string, saved in the variable %VAR% to lower-case characters, because it's always upper-case:

I guess you could use the left string / right string batch equivalents.

set VAR=%COMPUTERNAME:~0,1%%COMPUTERNAME:~-1%

echo %VAR%

Thank you

I suppose you could just use this:

ChCaseCN.cmd

@ECHO OFF&SETLOCAL
SET VAR=%COMPUTERNAME:~0,1%%COMPUTERNAME:~-1%
PUSHD %TEMP%
TYPE NUL>%VAR%.yzl
FOR /F "DELIMS=." %%# IN ('DIR/B/L %VAR%.yzl') DO SET VAR=%%#
DEL %VAR%.yzl
ECHO=%%VAR%%=%VAR%
POPD&PAUSE

  • Author

Hi there,

thank you Yzöwl, it's working perfectly for me.

Edited by HØLLØW

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.