Modify

Opened 16 months ago

Last modified 2 weeks ago

#3696 assigned Feature Request

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

Reported by: argumentum Owned by: BrewManNH
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 (4)

comment:1 follow-up: Changed 16 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 16 months 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 15 months 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

comment:4 Changed 2 weeks ago by Jpm

  • Owner set to BrewManNH
  • Status changed from new to assigned

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 assigned The owner will remain BrewManNH.
Author


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

 
Note: See TracTickets for help on using tickets.