2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

#1 Post by Jer » 26 Aug 2017 16:23

Has this issue been addressed yet, where code copied from this forum includes ascii #160 character
where the code is indented? Is this an issue with Windows 10 and/or microsoft edge browser?

I am using Firefox browser on a Windows 10 64bit PC for this thread and will check to see if my code copied
back to file has the same problem, characters that need to be edited out before the batch file will execute.

I would like your guidance on working with code blocks and variables not being recognized inside the block.
Thanks for setting me straight on this. Here is my puzzling code:

Code: Select all

@echo off & setlocal EnableDelayedExpansion
Set "array[0]=word3"
Set "array[1]=word2"
Set "array[2]=word1"

echo array before: & set array[

Set "idx1=0" & Set "idx2=2"
If 1 equ 1 (
  Set "var=!array[%idx1%]!"
  Set "array[%idx1%]=!array[%idx2%]!"
  rem wrong syntax: Set "array(%idx2%]=!var!"
  rem should be:
  Set "array[%idx2%]=!var!"
)
echo( & echo var: %var%  - array after: & set array[

endlocal & pause & exit /b


and the result:
array before:
array[0]=word3
array[1]=word2
array[2]=word1

var: word3 - array after:
array[0]=word1
array[1]=word2
array[2]=word1


I copied my batch code from this thread to a new file and it ran without the ascii char #160 issue.
Last edited by Jer on 26 Aug 2017 19:41, edited 2 times in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: 2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

#2 Post by aGerman » 26 Aug 2017 16:34

This is an issue of Edge. I already reported it. Meanwhile it was fixed but not yet rolled out with any update. See
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11004541/

As to your second question - I can't help as long as I don't know the expected result.

Steffen

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: 2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

#3 Post by Jer » 26 Aug 2017 19:17

Oops. Set "array( is my problem in the code. It should have a square open bracket: Set "array[

Thanks aGerman for the information about MS edge browser and the issue with copying and
pasting code in forums.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: 2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

#4 Post by penpen » 26 Aug 2017 19:34

Edit: Sorry, i misunderstood the issue, Please ignore this post.

To avoid browser related posting issues, you could use "genchr.cmd" to create the problematic character:
http://www.dostips.com/forum/viewtopic.php?f=3&t=5326.


penpen

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: 2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

#5 Post by aGerman » 27 Aug 2017 04:47

@penpen

We are really talking about a bug in Edge that isn't related to the forum software. Contiguous space characters (like in indentations) are converted to non-breaking spaces that cause erros if you copy the code back. Just see my link.

Steffen

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: 2 questions: 1) copying code to forum & Windows 10 2) how to rearrange an array?

#6 Post by pieh-ejdsch » 27 Aug 2017 06:14

Hello,

You can also turn an array around easier:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set "a[0]=0 abc"
set "a[1]=1 def"
set "a[2]=2 ghi"
set "a[3]=3 jkl"

set /a startArray=0 , stopArray=3

set a[
for /L %%I in (%startArray% 1 %stopArray%) do (
  for /L %%i in (%stopArray% -1 %startArray%) do (
    >nul 2>&1 set /a "x=1/(startArray+stopArray-%%I-%%i)" || (
      set "temp[%%I]=!a[%%i]!"
) ) )
for /L %%I in (%startArray% 1 %stopArray%) do (
  set "a[%%I]=!temp[%%I]!
  set "temp[%%I]="
)

set a[


Phil

Post Reply