Modify

Opened 2 months ago

Last modified 7 weeks ago

#3696 new Feature Request

Func _ArrayFromString($s, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0)

Reported by: argumentum Owned by:
Milestone: Component: Standard UDFs
Version: Severity: None
Keywords: _ArrayFromString Cc:

Description

; #FUNCTION# ====================================================================================================================
; Author ........: argumentum ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/
; Modified.......:
; ===============================================================================================================================
Func _ArrayFromString($s, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0)
	Local $m, $n, $b, $c = StringSplit($s, $sDelim_Row, 3)
	$b = StringSplit($c[0], $sDelim_Col, 3)
	If UBound($c) = 1 And Not $iForce2D Then
		For $m = 0 To UBound($b) - 1
			$b[$m] = StringStripWS($b[$m], 3)
			If $b[$m] == Int($b[$m]) Then $b[$m] = Int($b[$m])
		Next
		Return $b
	EndIf
	Local $a[UBound($c)][UBound($b)]
	For $n = 0 To UBound($c) - 1
		$b = StringSplit($c[$n], $sDelim_Col, 3)
		If UBound($b) > UBound($a, 2) Then Return SetError(1)
		For $m = 0 To UBound($b) - 1
			$b[$m] = StringStripWS($b[$m], 3)
			If $b[$m] == Int($b[$m]) Then $b[$m] = Int($b[$m])
			$a[$n][$m] = $b[$m]
		Next
	Next
	Return $a
EndFunc   ;==>_ArrayFromString

This function reconstructs an "array to text" created with _ArrayToString() and proposed change to _SQLite_Display2DResult() on ticket https://www.autoitscript.com/trac/autoit/ticket/3695#ticket.

Test code is at https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/

This addition is not code braking.

Attachments (0)

Change History (3)

comment:1 follow-up: Changed 2 months ago by BrewManNH

If $b[$m] == Int($b[$m])

Don't use the double equals sign in comparisons unless you want to do a case sensitive comparison, and in this example from your code would be silly to do.

comment:2 in reply to: ↑ 1 Changed 8 weeks ago by argumentum

Replying to BrewManNH:

If $b[$m] == Int($b[$m])

Don't use the double equals sign in comparisons ...

Regardless of the "double equals" or not, the idea is sound and the code is functional as is.
If it needs correction, just change it on the final review.

comment:3 Changed 7 weeks ago by argumentum

The string to int. idea is just wrong. ( https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/?do=findComment&comment=1419627 )
With those lines removed, the revised code would be:

Func _ArrayFromString($s, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/
	Local $m, $n, $b, $c = StringSplit($s, $sDelim_Row, 3)
	$b = StringSplit($c[0], $sDelim_Col, 3)
	If UBound($c) = 1 And Not $iForce2D Then Return $b
	Local $a[UBound($c)][UBound($b)]
	For $n = 0 To UBound($c) - 1
		$b = StringSplit($c[$n], $sDelim_Col, 3)
		If UBound($b) > UBound($a, 2) Then Return SetError(1)
		For $m = 0 To UBound($b) - 1
			$a[$n][$m] = $b[$m]
		Next
	Next
	Return $a
EndFunc   ;==>_ArrayFromString

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as new The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.