Jump to content

Ini Text


wolf9228
 Share

Recommended Posts

IniText.Zip

IniText.zip

Simple mistake ... Has been added the StringStripWS function

New script

IniText.zip

IniText.au3

#include <Array.au3>

$Text = ""
$Text = IniWriteText($Text,"  Section1","      Key1","Valuer1",True)
$Text = IniWriteText($Text,"Section1","Key2","Valuer2",True)
$Text = IniWriteText($Text,"Section1","Key3","Valuer3",True)
$Text = IniWriteText($Text,"Section1","Key4","Valuer4",True)
$Text = IniWriteText($Text,"Section1","Key5","Valuer5",True)

$RTA = IniReadText($Text,"Section1","Key1","",True)
$RTB = IniReadText($Text,"Section1","Key2","",True)
$RTC = IniReadText($Text,"Section1","Key3","",True)
$RTD = IniReadText($Text,"Section1","Key4","",True)
$RTE = IniReadText($Text,"Section1","Key5","",True)
MsgBox(0,"IniReadText", _ 
"Section1 Key1 ==> " & $RTA & @CRLF & _
"Section1 Key2 ==> " & $RTB & @CRLF & _
"Section1 Key3 ==> " & $RTC & @CRLF & _
"Section1 Key4 ==> " & $RTD & @CRLF & _
"Section1 Key5 ==> " & $RTE , 0)

$Text = IniWriteText($Text,"Section2","Key1","Valuer1",True)
$Text = IniWriteText($Text,"Section2","Key2","Valuer2",True)
$Text = IniWriteText($Text,"Section2","Key3","Valuer3",True)
$Text = IniWriteText($Text,"Section2","Key4","Valuer4",True)
$Text = IniWriteText($Text,"Section2","Key5","Valuer5",True)

$RTA = IniReadText($Text,"Section2","Key1","",True)
$RTB = IniReadText($Text,"Section2","Key2","",True)
$RTC = IniReadText($Text,"Section2","Key3","",True)
$RTD = IniReadText($Text,"Section2","Key4","",True)
$RTE = IniReadText($Text,"Section2","Key5","",True)
MsgBox(0,"IniReadText", _ 
"Section2 Key1 ==> " & $RTA & @CRLF & _
"Section2 Key2 ==> " & $RTB & @CRLF & _
"Section2 Key3 ==> " & $RTC & @CRLF & _
"Section2 Key4 ==> " & $RTD & @CRLF & _
"Section2 Key5 ==> " & $RTE , 0)

$Text = IniWriteText($Text,"Section3","Key1","Valuer1",True)
$Text = IniWriteText($Text,"Section3","Key2","Valuer2",True)
$Text = IniWriteText($Text,"Section3","Key3","Valuer3",True)
$Text = IniWriteText($Text,"Section3","Key4","Valuer4",True)
$Text = IniWriteText($Text,"Section3","Key5","Valuer5",True)

$RTA = IniReadText($Text,"Section3","Key1","",True)
$RTB = IniReadText($Text,"Section3","Key2","",True)
$RTC = IniReadText($Text,"Section3","Key3","",True)
$RTD = IniReadText($Text,"Section3","Key4","",True)
$RTE = IniReadText($Text,"Section3","Key5","",True)
MsgBox(0,"IniReadText", _ 
"Section3 Key1 ==> " & $RTA & @CRLF & _
"Section3 Key2 ==> " & $RTB & @CRLF & _
"Section3 Key3 ==> " & $RTC & @CRLF & _
"Section3 Key4 ==> " & $RTD & @CRLF & _
"Section3 Key5 ==> " & $RTE , 0)

$RTArray = IniReadSectionText($Text,"Section3",True)
_ArrayDisplay($RTArray, "Section3")

$SectionData = ""
For $i = 1 To 10
$SectionData = IniMakeSectionData("Key" & $i,"Value" & $i,$SectionData,True)
Next
$Text = IniWriteSectionText($Text,"Section4",$SectionData,True)
$RTArray = IniReadSectionText($Text,"Section4",True)
_ArrayDisplay($RTArray, "Section4")

$RTArray = IniReadSectionNamesText($Text,True)
_ArrayDisplay($RTArray, "Section Names")

Func IniWriteText($Text,$Section,$Key,$Value,$Binary = False)
$Section = StringStripWS ($Section,3)
$Key = StringStripWS ($Key,3)
if ($Binary) Then
if StringInStr($Section,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Section,@LF) Then Return SetError(1,0,$Text)
if StringInStr($Key,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Key,@LF) Then Return SetError(1,0,$Text)
$Text = BinaryToString($Text)
Else
if StringInStr($Section,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Section,@LF) Then Return SetError(1,0,$Text)
if StringInStr($Key,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Key,@LF) Then Return SetError(1,0,$Text)
if StringInStr($Value,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Value,@LF) Then Return SetError(1,0,$Text)
EndIf
$TLen = StringLen($Text)
$PosA = IsSection($Text,$Section)
if ($PosA) Then
$PosB = IsKey($Text,$Key,$PosA)
if ($PosB) Then
For $A = $PosB To $TLen
$CharA = StringMid($Text,$A,2)
if StringIsCRLF($CharA) Or $A = $TLen Then
if (StringIsCRLF($CharA)) Then $A -= 1
$TextA = StringLeft($Text,$PosB)
$TextB = StringRight($Text,$TLen - $A)
if ($Binary) Then
$TextA = StringAdd($TextA,String(StringToBinary($Value)))
Else
$TextA = StringAdd($TextA,$Value)
EndIf
$TextA = StringAdd($TextA,$TextB)
if ($Binary) Then
return SetError(0,0,String(StringToBinary($TextA)))
Else
return SetError(0,0,$TextA)
EndIf
EndIf
Next
Else
$CharB = StringMid($Text,$PosA,2)
if StringIsCRLF($CharB) Then $PosA += 1
$TextA = StringLeft($Text,$PosA)
$TextB = StringRight($Text,$TLen - $PosA)
if Not StringIsCRLF($CharB) Then $TextA = StringAdd($TextA,@CRLF)
$TextA = StringAdd($TextA,$Key)
$TextA = StringAdd($TextA,"=")
if ($Binary) Then
$TextA = StringAdd($TextA,String(StringToBinary($Value)))
Else
$TextA = StringAdd($TextA,$Value)
EndIf
$TextA = StringAdd($TextA,@CRLF)
$TextA = StringAdd($TextA,$TextB)
if ($Binary) Then
return SetError(0,0,String(StringToBinary($TextA)))
Else
return SetError(0,0,$TextA)
EndIf
EndIf
EndIf
$CharC = StringRight($Text,2)
if Not StringIsCRLF($CharC) Then $Text = StringAdd($Text,@CRLF)
$Text = StringAdd($Text,"[")
$Text = StringAdd($Text,$Section)
$Text = StringAdd($Text,"]")
$Text = StringAdd($Text,@CRLF)
$Text = StringAdd($Text,$Key)
$Text = StringAdd($Text,"=")
if ($Binary) Then
$Text = StringAdd($Text,String(StringToBinary($Value)))
Else
$Text = StringAdd($Text,$Value)
EndIf
$Text = StringAdd($Text,@CRLF)
if ($Binary) Then
return SetError(0,0,String(StringToBinary($Text)))
Else
return SetError(0,0,$Text)
EndIf
EndFunc

Func IniReadText($Text,$Section,$Key,$Default,$Binary = False)
$Section = StringStripWS ($Section,3)
$Key = StringStripWS ($Key,3)
if ($Binary) Then $Text = BinaryToString($Text)
if StringInStr($Section,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Section,@LF) Then Return SetError(1,0,$Text)
if StringInStr($Key,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Key,@LF) Then Return SetError(1,0,$Text)
$TLen = StringLen($Text)
$PosA = IsSection($Text,$Section)
if ($PosA) Then
$PosB = IsKey($Text,$Key,$PosA)
if ($PosB) Then
For $A = $PosB To $TLen
$CharA = StringMid($Text,$A,2)
if StringIsCRLF($CharA) Or $A = $TLen Then 
if ($Binary) Then
return SetError(0,0,BinaryToString(StringMid($Text,($PosB + 1),$A - ($PosB + 1))))
Else
return SetError(0,0,StringMid($Text,($PosB + 1),$A - ($PosB + 1)))
EndIf
EndIf
Next
Else
return SetError(1,0,$Default)
EndIf
EndIf
return SetError(2,0,$Default)
EndFunc

Func IniMakeSectionData($Key,$Value,$SectionData = "",$Binary = False)
$Key = StringStripWS ($Key,3)
$SectionData = StringAdd($SectionData,$Key)
$SectionData = StringAdd($SectionData,"=")
if ($Binary) Then
$SectionData = StringAdd($SectionData,StringToBinary($Value))
Else
$SectionData = StringAdd($SectionData,$Value)
EndIf
$SectionData = StringAdd($SectionData,@CRLF)
Return SetError(0,0,$SectionData)
EndFunc

Func IniWriteSectionText($Text,$Section,$SectionData,$Binary = False)
$Section = StringStripWS ($Section,3)
if ($Binary) Then $Text = BinaryToString($Text)
if StringInStr($Section,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Section,@LF) Then Return SetError(1,0,$Text)
$TLen = StringLen($Text)
$PosA = IsSection($Text,$Section)
if ($PosA) Then
For $A = $PosA To $TLen
$CharA = StringMid($Text,$A,2)
if StringIsCRLF($CharA) Then
$PosB = IsNewSection($Text,$A)
if ($PosB) Then
$SectionData = "[" & $Section & "]" & @CRLF & $SectionData
$PosA -= (StringLen($Section) + 5) ;5 = LenOf @CRLF & "[]" + 1 
$PosB -= (StringLen($Section) + 3) ;3 = LenOf @CRLF + 1
$TextA = StringLeft($Text,$PosA)
$TextB = StringRight($Text,$TLen - $PosB)
$TextA = StringAdd($TextA,@CRLF)
$TextA = StringAdd($TextA,$SectionData)
$TextA = StringAdd($TextA,$TextB)
if ($Binary) Then
return SetError(0,0,String(StringToBinary($TextA)))
Else
return SetError(0,0,$TextA)
EndIf
EndIf
EndIf
Next
$SectionData = "[" & $Section & "]" & @CRLF & $SectionData
$PosA -= (StringLen($Section) + 5) ;5 = LenOf @CRLF & "[]" + 1
$PosB = $TLen
$TextA = StringLeft($Text,$PosA)
$TextA = StringAdd($TextA,@CRLF)
$TextA = StringAdd($TextA,$SectionData)
if ($Binary) Then
return SetError(0,0,String(StringToBinary($TextA)))
Else
return SetError(0,0,$TextA)
EndIf
Else
$SectionData = "[" & $Section & "]" & @CRLF & $SectionData
$CharC = StringMid($Text,$TLen - 1,2)
if Not StringIsCRLF($CharC) Then _ 
$Text = StringAdd($Text,@CRLF)
$TextA = StringAdd($Text,$SectionData)
if ($Binary) Then
return SetError(0,0,String(StringToBinary($TextA)))
Else
return SetError(0,0,$TextA)
EndIf
EndIf
EndFunc

Func IniReadSectionText($Text,$Section,$Binary = False)
$Section = StringStripWS ($Section,3)
if ($Binary) Then $Text = BinaryToString($Text)
if StringInStr($Section,@CR) Then Return SetError(1,0,$Text)
if StringInStr($Section,@LF) Then Return SetError(1,0,$Text)
$TLen = StringLen($Text)
Local $RTArray[1][2] , $UBound = 0
$PosA = IsSection($Text,$Section)
if ($PosA) Then
For $A = $PosA To $TLen
$CharA = StringMid($Text,$A,1)
if (Not CharIsSpace($CharA)) Then
For $B = $A To $TLen
$CharB = StringMid($Text,$B,2)
if StringIsCRLF($CharB) Then
if IsNewSection($Text,$B) Then Return SetError(0,0,$RTArray)
$B = StringExceedsCRLF($Text,$B)
For $C = $B To $TLen
$CharC = StringMid($Text,$C,1)
if (Not CharIsSpace($CharC)) Then
For $D = $C To $TLen
$CharD = StringMid($Text,$D,1)
if (StringCompare($CharC,"=") = 0) Then
For $E = $D To $TLen
$CharE = StringMid($Text,$E,2)
if (StringIsCRLF($CharE) Or $E = $TLen) Then
$UBound += 1 
ReDim $RTArray[$UBound][2]
if ($Binary) Then
$RTArray[$UBound - 1][0] = StringMid($Text,$B,(($D - 1) - $B) + 1)
$RTArray[$UBound - 1][1] = BinaryToString(StringMid($Text,($D + 1),(($E - 1) - ($D - 1)) - 1))
Else
$RTArray[$UBound - 1][0] = StringMid($Text,$B,(($D - 1) - $B) + 1)
$RTArray[$UBound - 1][1] = StringMid($Text,($D + 1),(($E - 1) - ($D - 1)) - 1)
EndIf
ExitLoop 3
EndIf
Next
EndIf
Next
EndIf
Next
EndIf
Next
ExitLoop
EndIf
Next
EndIf
if ($PosA) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndFunc

Func IniReadSectionNamesText($Text,$Binary = False)
if ($Binary) Then $Text = BinaryToString($Text)
$TLen = StringLen($Text)
Local $RTArray[1][2] , $UBound = 0
For $A = 1 To $TLen
$CharA = StringMid($Text,$A,2)
if (StringIsCRLF($CharA) Or $A = 1) Then
$A = StringExceedsCRLF($Text,$A)
For $B = $A To $TLen
$CharB = StringMid($Text,$B,1)
if (Not CharIsSpace($CharB)) Then
For $C = $B To $TLen
$CharC = StringMid($Text,$C,1)
if (StringCompare($CharC,"[") = 0) Then
For $D = $C + 1 To $TLen
$CharD = StringMid($Text,$D,1)
if (Not CharIsSpace($CharD)) Then
For $E = $D To $TLen
$CharE = StringMid($Text,$E,1)
if (Not CharIsSpace($CharE)) Then
For $F = $E To $TLen
$CharF = StringMid($Text,$F,1)
if (StringCompare($CharF,"]") = 0) Then 
if ($F = $TLen) Then
$UBound += 1
ReDim $RTArray[$UBound]
$RTArray[$UBound - 1] = StringMid($Text,$D,$F - $D)
Return $RTArray
EndIf
For $G = $F + 1 To $TLen
$CharG = StringMid($Text,$G,1)
$CharH = StringMid($Text,$G,2)
if (Not CharIsSpace($CharG)) Then
if (StringIsCRLF($CharH)) Then
$UBound += 1
ReDim $RTArray[$UBound]
$RTArray[$UBound - 1] = StringMid($Text,$D,$F - $D)
ExitLoop 6
Else
if ($G = $TLen) Then
$UBound += 1
ReDim $RTArray[$UBound]
$RTArray[$UBound - 1] = StringMid($Text,$D,$F - $D)
Return $RTArray
EndIf
ExitLoop 6
EndIf
EndIf
if ($G = $TLen) Then
$UBound += 1
ReDim $RTArray[$UBound]
$RTArray[$UBound - 1] = StringMid($Text,$D,$F - $D)
Return SetError(0,0,$RTArray)
EndIf
Next
Else
EndIf
if ($F = $TLen) Then 
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndIf
Next
EndIf
if ($E = $TLen) Then 
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndIf
Next
EndIf
if ($D = $TLen) Then 
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndIf
Next
Else
ExitLoop 2
EndIf
if ($C = $TLen) Then 
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndIf
Next
EndIf
if ($B = $TLen) Then 
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndIf
Next
EndIf
if ($A = $TLen) Then 
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndIf
Next
if ($UBound > 0) Then
Return SetError(0,0,$RTArray)
Else
Return SetError(1,0,$RTArray)
EndIf
EndFunc

Func IsSection($Text,$Section)
$TLen = StringLen($Text)
$SLen = StringLen($Section)
$Section = StringUpper($Section)
For $A = 1 To $TLen
$CharA = StringMid($Text,$A,2)
if (StringIsCRLF($CharA) Or $A = 1) Then
$A = StringExceedsCRLF($Text,$A)
For $B = $A To $TLen
$CharB = StringMid($Text,$B,1)
if (Not CharIsSpace($CharB)) Then
For $C = $B To $TLen
$CharC = StringMid($Text,$C,1)
if (StringCompare($CharC,"[") = 0) Then
For $D = $C + 1 To $TLen
$CharD = StringMid($Text,$D,1)
if (Not CharIsSpace($CharD)) Then
if (StringCompare(StringUpper(StringMid($Text,$D,$SLen)),$Section) = 0) Then
For $E = $D + $SLen To $TLen
$CharE = StringMid($Text,$E,1)
if (Not CharIsSpace($CharE)) Then
For $F = $E To $TLen
$CharF = StringMid($Text,$F,1)
if (StringCompare($CharF,"]") = 0) Then 
if ($F = $TLen) Then return $F
For $G = $F + 1 To $TLen
$CharG = StringMid($Text,$G,1)
$CharH = StringMid($Text,$G,2)
if (Not CharIsSpace($CharG)) Then
if (StringIsCRLF($CharH)) Then
return $G 
Else
if ($G = $TLen) Then return $G
ExitLoop 6
EndIf
EndIf
if ($G = $TLen) Then return $G
Next
Else
ExitLoop 5
EndIf
if ($F = $TLen) Then return 0
Next
EndIf
if ($E = $TLen) Then return 0
Next
Else
ExitLoop 3
EndIf
EndIf
if ($D = $TLen) Then return 0
Next
Else
ExitLoop 2
EndIf
if ($C = $TLen) Then return 0
Next
EndIf
if ($B = $TLen) Then return 0
Next
EndIf
if ($A = $TLen) Then return 0
Next
return 0
EndFunc

Func IsNewSection($Text,$Pos)
$TLen = StringLen($Text)
For $A = $Pos To $TLen
$CharA = StringMid($Text,$A,2)
if (StringIsCRLF($CharA)) Then
$A = StringExceedsCRLF($Text,$A)
For $B = $A To $TLen
$CharB = StringMid($Text,$B,1)
if (Not CharIsSpace($CharB)) Then
For $C = $B To $TLen
$CharC = StringMid($Text,$C,1)
if (StringCompare($CharC,"[") = 0) Then
For $D = $C + 1 To $TLen
$CharD = StringMid($Text,$D,1)
$CharE = StringMid($Text,$D,2)
if StringIsCRLF($CharE) Or $D = $TLen Then Return 0
if (StringCompare($CharD,"]") = 0) Then
For $E = $D + 1 To $TLen
$CharE = StringMid($Text,$E,1)
$CharF = StringMid($Text,$E,2)
if (Not CharIsSpace($CharE)) Then
if StringIsCRLF($CharF) Or $E = $TLen Then 
Return $E
Else
Return 0
EndIf
EndIf
Next
if $D = $TLen Then Return $D
EndIf
if $D = $TLen Then Return 0
Next
Else
return 0
EndIf
if $C = $TLen Then Return 0
Next
EndIf
if $B = $TLen Then Return 0
Next
EndIf
if $A = $TLen Then Return 0
Next
return 0
EndFunc

Func IsKey($Text,$Key,$Pos)
$TLen = StringLen($Text)
$KLen = StringLen($Key)
$Key = StringUpper($Key)
For $A = $Pos To $TLen
$CharA = StringMid($Text,$A,1)
if (Not CharIsSpace($CharA)) Then
For $B = $A To $TLen
$CharB = StringMid($Text,$B,2)
if StringIsCRLF($CharB) Then
if IsNewSection($Text,$B) Then Return 0
$B = StringExceedsCRLF($Text,$B)
For $C = $B To $TLen
$CharC = StringMid($Text,$C,1)
if (Not CharIsSpace($CharC)) Then
For $D = $C To $TLen
if (StringCompare(StringUpper(StringMid($Text,$D,$KLen)),$Key) = 0) Then
For $E = $D + $KLen To $TLen
$CharD = StringMid($Text,$E,1)
if (Not CharIsSpace($CharD)) Then
For $F = $E To $TLen
$CharE = StringMid($Text,$F,1)
if (StringCompare($CharE,"=") = 0) Then 
Return $F
Else
ExitLoop 4
EndIf
Next
EndIf
Next
Else
ExitLoop 2
EndIf
Next
EndIf
Next
EndIf
Next
ExitLoop
EndIf
Next
return 0
EndFunc

Func StringExceedsCRLF($Text,$Pos)
$A = $Pos
$TLen = StringLen($Text)
While $A <> $TLen
$CharA = StringMid($Text,$A,1)
if StringCompare($CharA,@CR) <> 0 And _ 
StringCompare($CharA,@LF) <> 0 Then ExitLoop
$A += 1
WEnd
Return $A
EndFunc

Func StringAdd($StringA,$StringB)
Return $StringA & $StringB
EndFunc

Func CharIsSpace($CharA)
if StringCompare($CharA," ") = 0 Then Return 1
Return 0
EndFunc

Func StringIsCRLF($String)
if StringCompare($String,@CRLF) = 0 Then Return 1
Return 0
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

What exactly is this supposed to do? There's no description or comments in the code.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

What exactly is this supposed to do? There's no description or comments in the code.

Have you ever seen the Ini file functions in the Autoit help file

What will I explain? Here are the links

Function Reference

IniRead

http://www.autoitscript.com/autoit3/docs/functions/IniRead.htm

Function Reference

IniWrite

http://www.autoitscript.com/autoit3/docs/functions/IniWrite.htm

Function Reference

IniReadSection

http://www.autoitscript.com/autoit3/docs/functions/IniReadSection.htm

Function Reference

IniWriteSection

http://www.autoitscript.com/autoit3/docs/functions/IniWriteSection.htm

Function Reference

IniReadSectionNames

http://www.autoitscript.com/autoit3/docs/functions/IniReadSectionNames.htm

صرح السماء كان هنا

 

Link to comment
Share on other sites

BrewManNH is aware of these Functions! :unsure: I would highly recommend looking at Switch...Case...EndSwitch especially if you have a lot of If...ElseIf..Else Statements, as I have heard on the Forum that Switch can sometimes be a little bit quicker.

Also what makes your Functions different from the Native INI Functions? Or _IniString?

Edited by guinness

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

As guiness said, I am aware of those functions. What exactly does THIS do is my question?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH is aware of these Functions! :unsure: I would highly recommend looking at Switch...Case...EndSwitch especially if you have a lot of If...ElseIf..Else Statements, as I have heard on the Forum that Switch can sometimes be a little bit quicker.

Also what makes your Functions different from the Native INI Functions? Or _IniString?

Really can avoid some of the statement if ... But they are few and operations Logical coherent and a bit complicated so I preferred to use a statement If absolutely ... Thank you

صرح السماء كان هنا

 

Link to comment
Share on other sites

What exactly does THIS do is my question?

The same as Ini* but without using the file (string/text variable instead).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

The same as Ini* but without using the file (string/text variable instead).

Ahhh, ok. I don't see much use of it then for what I do, but good to know. I was wondering why it had no file functions and thought that might have been the purpose of it but, as I said, no comments or description was forthcoming from wolf9228 and I didn't want to try and dig through all this code just to see what it was for. :unsure:

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ahhh, ok. I don't see much use of it then for what I do, but good to know. I was wondering why it had no file functions and thought that might have been the purpose of it but, as I said, no comments or description was forthcoming from wolf9228 and I didn't want to try and dig through all this code just to see what it was for. :>

You could just have followed the link MrCreatoR posted...

:unsure:

Link to comment
Share on other sites

You could just have followed the link MrCreatoR posted...

:unsure:

I did follow the link, that didn't tell me if this was the same thing or different, and because I didn't get an answer from wolf9228, and his response to the link wasn't exactly telling me much either, I was still in the dark as to what the purpose of this script was.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH

guinness

AdmiralAlkex

MrCreatoR

All are welcome to my page modest And thank you for the valuable participation

Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

Project Compiler C + +

All Project File

Project Compiler C + +

IniFile.h

#include <string.h>
#include <ctype.h>
#include <stdio.h>
char* StringMid(char* iString,int Start,int Count);
char* StringLeft(char* iString,int Count);
char* StringRight(char* iString,int Count);
char* StringStripWS(char* iString);
char* StringAdd(char* StrA,char* StrB);
char* StringUpper(char* iString);
int CharIsSpace(char* CharA);
int StringIsCRLF(char* iString);
int StringExceedsCRLF(char* Text,int Pos);
char* CRLF();
int IsSection(char* Text,char* Section);
int IsKey(char* Text,char* Key,int Pos);
int IsNewSection(char* Text,int Pos);
char* StringIniWrite(char* Text,char* Section,char* Key,char* Value);
char* StringIniRead(char* Text,char* Section,char* Key,char* iDefault);
int FileIniWrite(char* FileFullName,char* Section,char* Key,char* Value);
char* FileIniRead(char* Text,char* Section,char* Key,char* iDefault);

int FileIniWrite(char* FileFullName,char* Section,char* Key,char* Value)
{
FILE * pFile = fopen (FileFullName,"rb");
if (pFile == NULL )
{
FILE * nFile = fopen (FileFullName,"wb");
if (nFile == NULL) return 0;
char* Text = StringIniWrite("",Section,Key,Value);
fwrite(Text,1,strlen(Text) + 1,nFile);
fclose(nFile);
} else {
fseek(pFile,0,SEEK_END);
int FileSize = ftell(pFile);
rewind(pFile);
char* Text = new char[FileSize];
ZeroMemory(Text,FileSize);
fread(Text,FileSize,1,pFile);
Text = StringIniWrite(Text,Section,Key,Value);
fclose(pFile);
pFile = fopen (FileFullName,"wb");
if (pFile == NULL) return 0;
fwrite(Text,1,strlen(Text) + 1,pFile);
fclose(pFile);
}

return 1;
}

char* FileIniRead(char* FileFullName,char* Section,char* Key,char* iDefault)
{
FILE * pFile = fopen (FileFullName,"rb");
if (pFile == NULL ) return iDefault;
fseek(pFile,0,SEEK_END);
int FileSize = ftell(pFile);
rewind(pFile);
char* Text = new char[FileSize];
ZeroMemory(Text,FileSize);
fread(Text,FileSize,1,pFile);
fclose(pFile);
return StringIniRead(Text,Section,Key,iDefault);
}

char* StringIniRead(char* Text,char* Section,char* Key,char* iDefault)
{
Section = StringStripWS(Section);
Key = StringStripWS(Key);
int TLen = strlen(Text);
int PosA = IsSection(Text,Section);
if (PosA)
{
int PosB = IsKey(Text,Key,PosA);
if (PosB)
{
for (int A = PosB; A <= TLen ; A++)
{
char* CharA = StringMid(Text,A,2);
if ((StringIsCRLF(CharA)) || A == TLen)
return StringMid(Text,(PosB + 1),A - (PosB + 1));
}
}else {
return iDefault;
}
}
return iDefault;
}

char* StringIniWrite(char* Text,char* Section,char* Key,char* Value)
{
Section = StringStripWS(Section);
Key = StringStripWS(Key);
int TLen = strlen(Text);
int PosA = IsSection(Text,Section);
if (PosA)
{
int PosB = IsKey(Text,Key,PosA);
if (PosB)
{
for (int A = PosB; A <= TLen ; A++)
{
char* CharA = StringMid(Text,A,2);
if ((StringIsCRLF(CharA)) || A == TLen)
{
if (StringIsCRLF(CharA)) A--;
char* TextA = StringLeft(Text,PosB);
char* TextB = StringRight(Text,TLen - A);
TextA = StringAdd(TextA,Value);
TextA = StringAdd(TextA,TextB);
return TextA;
}
}
}else {
char* CharB = StringMid(Text,PosA,2);
if (StringIsCRLF(CharB)) PosA++;
char* TextA = StringLeft(Text,PosA);
char* TextB = StringRight(Text,TLen - PosA);
if (!StringIsCRLF(CharB)) TextA = StringAdd(TextA,CRLF());
TextA = StringAdd(TextA,Key);
TextA = StringAdd(TextA,"=");
TextA = StringAdd(TextA,Value);
TextA = StringAdd(TextA,CRLF());
TextA = StringAdd(TextA,TextB);
return TextA;
}
}
char* CharC = StringRight(Text,2);
if (!StringIsCRLF(CharC)) Text = StringAdd(Text,CRLF());
Text = StringAdd(Text,"[");
Text = StringAdd(Text,Section);
Text = StringAdd(Text,"]");
Text = StringAdd(Text,CRLF());
Text = StringAdd(Text,Key);
Text = StringAdd(Text,"=");
Text = StringAdd(Text,Value);
Text = StringAdd(Text,CRLF());
return Text;
}

int IsSection(char* Text,char* Section)
{
int TLen = strlen(Text);
int SLen = strlen(Section);
int ExitLoop = 0;
Section = StringUpper(Section);
for (int A = 1; A <= TLen ; A++)
{
ExitLoop = 0;
char* CharA = StringMid(Text,A,2);
if ((StringIsCRLF(CharA)) || A == 1)
{
A = StringExceedsCRLF(Text,A);
for (int B = A; B <= TLen ; B++)
{
char* CharB = StringMid(Text,B,1);
if (!CharIsSpace(CharB))
{
for (int C = B; C <= TLen ; C++)
{
char* CharC = StringMid(Text,C,1);
if (strcmp(CharC,"[") == 0)
{
for (int D = C + 1; D <= TLen ; D++)
{
char* CharD = StringMid(Text,D,1);
if (!CharIsSpace(CharD))
{
if (strcmp(StringUpper(StringMid(Text,D,SLen)),Section) == 0)
{
for (int E = D + SLen; E <= TLen ; E++)
{
char* CharE = StringMid(Text,E,1);
if (!CharIsSpace(CharE))
{
for (int F = E; F <= TLen ; F++)
{
char* CharF = StringMid(Text,F,1);
if (strcmp(CharF,"]") == 0)
{
if (F == TLen) return F;
for (int G = F + 1; G <= TLen ; G++)
{
char* CharG = StringMid(Text,G,1);
char* CharH = StringMid(Text,G,2);
if (!CharIsSpace(CharG))
{
if (StringIsCRLF(CharH))
{
return G;
} else {
if (G == TLen) return G;
ExitLoop = 1;
break;
}
}
if (G == TLen) return G;
if (ExitLoop == 1) break;
}
} else {
ExitLoop = 1;
}
if (F == TLen) return 0;
if (ExitLoop == 1) break;
}
}
if (E == TLen) return 0;
if (ExitLoop == 1) break;
}
} else {
ExitLoop = 1;
}
}
if (D == TLen) return 0;
if (ExitLoop == 1) break;
}
} else {
ExitLoop = 1;
}
if (C == TLen) return 0;
if (ExitLoop == 1) break;
}
}
if (B == TLen) return 0;
if (ExitLoop == 1) break;
}
}
if (A == TLen) return 0;
}
return 0;
}

int IsNewSection(char* Text,int Pos)
{
int TLen = strlen(Text);
for (int A = Pos; A <= TLen ; A++)
{
char* CharA = StringMid(Text,A,2);
if (StringIsCRLF(CharA))
{
A = StringExceedsCRLF(Text,A);
for (int B = A; B <= TLen ; B++)
{
char* CharB = StringMid(Text,B,1);
if (!CharIsSpace(CharB))
{
for (int C = B; C <= TLen ; C++)
{
char* CharC = StringMid(Text,C,1);
if (strcmp(CharC,"[") == 0)
{
for (int D = C + 1; D <= TLen ; D++)
{
char* CharD = StringMid(Text,D,1);
char* CharE = StringMid(Text,D,2);
if (StringIsCRLF(CharE) || D == TLen) return 0;
if (strcmp(CharD,"]") == 0)
{
for (int E = D + 1; E <= TLen ; E++)
{
char* CharF = StringMid(Text,E,1);
char* CharG = StringMid(Text,E,2);
if (!CharIsSpace(CharF))
{
if (StringIsCRLF(CharG) || E == TLen)
{
return E;
} else {
return 0;
}
}
}
if (D == TLen) return D;
}
if (D == TLen) return 0;
}
} else {
return 0;
}
if (C == TLen) return 0;
}
}
if (B == TLen) return 0;
}
}
if (A == TLen) return 0;
}
return 0;
}

int IsKey(char* Text,char* Key,int Pos)
{
int TLen = strlen(Text);
int KLen = strlen(Key);
int ExitLoop = 0;
Key = StringUpper(Key);
for (int A = Pos; A <= TLen ; A++)
{
char* CharA = StringMid(Text,A,1);
if (!CharIsSpace(CharA))
{
for (int B = A; B <= TLen ; B++)
{
ExitLoop = 0;
char* CharB = StringMid(Text,B,2);
if (StringIsCRLF(CharB))
{
if (IsNewSection(Text,<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />) return 0;
B = StringExceedsCRLF(Text,<img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />;
for (int C = B; C <= TLen ; C++)
{
char* CharC = StringMid(Text,C,1);
if (!CharIsSpace(CharC))
{
for (int D = C; D <= TLen ; D++)
{
if (strcmp(StringUpper(StringMid(Text,D,KLen)),Key) == 0)
{
for (int E = D + KLen; E <= TLen ; E++)
{
char* CharD = StringMid(Text,E,1);
if (!CharIsSpace(CharD))
{
for (int F = E; F <= TLen ; F++)
{
char* CharE = StringMid(Text,F,1);
if (strcmp(CharE,"=") == 0)
{
return F;
} else {
ExitLoop = 1;
}
if (ExitLoop == 1) break;
}
}
if (ExitLoop == 1) break;
}
} else {
ExitLoop = 1;
}
if (ExitLoop == 1) break;
}
}
if (ExitLoop == 1) break;
}
}
}
}
}
return 0;
}

char* StringMid(char* iString,int Start,int Count)
{
int len = strlen(iString) , iCount = Count;
if (Start > len || Start < 0 || Count < 1) return "";
if (Count > (len - Start)) iCount == (len - Start);
return StringRight(StringLeft(iString,(Start + iCount) - 1),iCount);
}

char* StringLeft(char* iString,int Count)
{
if (Count < 1 ) return "";
if (Count > strlen(iString)) Count = strlen(iString);
char* StrA = new char[Count + 1];
strncpy(StrA,iString,Count);
StrA[Count]='\0';
return StrA;
}

char* StringRight(char* iString,int Count)
{
if (Count < 1 ) return "";
if (Count > strlen(iString)) Count = strlen(iString);
char* StrA = new char[Count + 1];
strncpy(StrA,iString + (strlen(iString) - Count),Count);
StrA[Count]='\0';
return StrA;
}

char* StringUpper(char* iString)
{
char* pString = new char[strlen(iString)];
for ( int i = 0 ; i <= strlen(iString) ; i++ )
pString[i] = toupper(iString[i]);
return pString;
}

char* StringStripWS(char* iString)
{
char* StrA = iString;
for ( int A = 0 ; A <= strlen(iString) ; A++ )
{
if (iString[A] == (char) 32) {StrA = StringRight(iString,strlen(iString) - A);} else {break;}
}
char* StrB = StrA;
for ( int A = strlen(StrA) ; A >= 0 ; A--)
{
if (StrA[A] == (char) 32) {StrB = StringLeft(StrA,A);} else {break;}
}
return StrB;
}

int StringIsCRLF(char* iString)
{
if (strcmp(iString ,CRLF()) == 0) return 1;
return 0;
}

int CharIsSpace(char* CharA)
{
if (strcmp(CharA," ") == 0) return 1;
return 0;
}

int StringExceedsCRLF(char* Text,int Pos)
{
int A = Pos;
int TLen = strlen(Text);
while (A != TLen)
{
char* CharA = StringMid(Text,A,1);
if (strcmp(CharA,"\r") != 0 && strcmp(CharA,"\n") != 0) break;
A++;
}
return A;
}

char* CRLF()
{
return StringAdd("\r","\n");
}

char* StringAdd(char* StrA,char* StrB)
{
char* StrC = new char[strlen(StrA) + strlen(StrB) + 1];
strcpy(StrC,StrA);
strcpy(StrC + strlen(StrA),StrB);
return StrC;
}

Project Compiler C + +

Example.cpp

#include <windows.h>
#include "IniFile.h"

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{

FileIniWrite("FileName.ini","Section1","Key1","value1");
FileIniWrite("FileName.ini","Section2","Key1","value1");
FileIniWrite("FileName.ini","Section3","Key1","value1");
FileIniWrite("FileName.ini","Section4","Key1","value1");
FileIniWrite("FileName.ini","Section5","Key1","value1");

char* RTA = FileIniRead("FileName.ini","Section1","Key1","NotFound");
char* RTB = FileIniRead("FileName.ini","Section2","Key1","NotFound");
char* RTC = FileIniRead("FileName.ini","Section3","Key1","NotFound");
char* RTD = FileIniRead("FileName.ini","Section4","Key1","NotFound");
char* RTE = FileIniRead("FileName.ini","Section5","Key1","NotFound");
char* RTF = FileIniRead("FileName.ini","Section5","Key2","NotFound");

char* RTText = StringAdd("","Section1 Key1 ==> ");
RTText = StringAdd(RTText,RTA);
RTText = StringAdd(RTText,CRLF());

RTText = StringAdd(RTText,"Section2 Key1 ==> ");
RTText = StringAdd(RTText,RTB);
RTText = StringAdd(RTText,CRLF());

RTText = StringAdd(RTText,"Section3 Key1 ==> ");
RTText = StringAdd(RTText,RTC);
RTText = StringAdd(RTText,CRLF());

RTText = StringAdd(RTText,"Section4 Key1 ==> ");
RTText = StringAdd(RTText,RTD);
RTText = StringAdd(RTText,CRLF());

RTText = StringAdd(RTText,"Section5 Key1 ==> ");
RTText = StringAdd(RTText,RTE);
RTText = StringAdd(RTText,CRLF());

RTText = StringAdd(RTText,"Section5 Key2 ==> ");
RTText = StringAdd(RTText,RTF);
RTText = StringAdd(RTText,CRLF());

MessageBox(0,RTText,"FileIniRead",0);


   return 0;
}

صرح السماء كان هنا

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...