Tuesday, March 17, 2020

Parse a Delimited String Into a String List (Delphi)

Parse a Delimited String Into a String List (Delphi) There are many times when you need to split a string into an array of strings by using a character as a separator. For example, a CSV (comma separated) file might have a line like Zarko;Gajic;;DelphiGuide and you want this line to be parsed into 4 lines (strings) Zarko, Gajic, (empty string) and DelphiGuide using the semi-colon character ; as a delimiter. Delphi provides several methods to parse a string, but you might find that neither one does exactly what you need. For example, the ExtractStrings RTL method always uses quote characters (single or double) for delimiters. Another approach is to use the ​Delimiter and ​DelimitedText properties of the TStrings class- but unfortunately, there is a bug in the implementation (inside Delphi) where the space character is always used as a delimiter. The only solution to parsing a delimited string is to write a method of your own: Delimited String Example ~~~~~~~~~~~~~~~~~~~~~~~~~procedure ParseDelimited(const sl : TStrings; const value : string; const delimiter : string) ;vardx : integer;ns : string;txt : string;delta : integer;begindelta : Length(delimiter) ;txt : value delimiter;sl.BeginUpdate;sl.Clear;trywhile Length(txt) 0 dobegindx : Pos(delimiter, txt) ;ns : Copy(txt,0,dx-1) ;sl.Add(ns) ;txt : Copy(txt,dxdelta,MaxInt) ;end;finallysl.EndUpdate;end;end;~~~~~~~~~~~~~~~~~~~~~~~~~ Usage (fills in Memo1) :ParseDelimited(Memo1.lines,Zarko;Gajic;;DelphiGuide,;)

Sunday, March 1, 2020

Biography of Sonni Ali, Songhai Monarch

Biography of Sonni Ali, Songhai Monarch Sonni Ali (birth date unknown; died 1492) was a  West African monarch who ruled Songhai from 1464 to 1492, expanding a small kingdom along the Niger River into one of medieval Africas greatest empires. Two divergent historical accounts of his life persist: the Muslim scholarly tradition that paints him as an infidel and tyrant and the oral Songhai tradition that remembers him as a great warrior and magician. Fast Facts: Sonni Ali Known For:  West African monarch of Songhai; expanded his empire, superseding the Mali empireAlso Known As:  Sunni Ali and Sonni Ali Ber (The Great)Born:  UnknownParents: Madogo (father); mothers name unknownDied:  1492Education: Traditional African arts education among the Faru of SokotoChildren: Sunni Baru Two Divergent Versions of Sonni Alis Life There are two main sources of information about Sonni Ali. One is in the Islamic chronicles of the period and the other is through Songhai oral tradition. These sources reflect two very different interpretations of Sonni Alis role in the development of the Songhai Empire. Early Life Little is known about Sonni Alis early life. He was schooled in the traditional African arts of the region and was well versed in the forms and techniques of warfare when he came to power in 1464 in the small kingdom of Songhai, which was centered around its capital city of Gao on the Niger River. He was the 15th consecutive ruler of the Sonni dynasty, which had begun in 1335. One of Alis ancestors, Sonni Sulaiman Mar, is said to have wrested Songhai away from the Mali Empire toward the end of the 14th century. Songhai Empire Takes Over Although Songhai had once paid tribute to the rulers of Mali, the Mali Empire was now crumbling and the time was right for Sonni Ali to lead his kingdom through a series of conquests at the old empires expense. By 1468, Sonni Ali had repulsed attacks by the Mossi to the south  and defeated the Dogon in the hills of Bandiagara. His first major conquest occurred in the following year when the Muslim leaders of Timbuktu, one of the great cities of the Mali Empire, asked for help against the Tuareg, the nomadic desert Berbers who had occupied the city since 1433. Sonni Ali took the opportunity not only to strike decisively against the Tuareg  but also against the city itself. Timbuktu became part of the fledgling Songhai Empire in 1469. Oral Tradition Sonni Ali is remembered in Songhai oral tradition as a magician of great power. Rather than following the Mali Empire system of Islamic city rule over a non-Islamic rural people, Sonni Ali mixed an unorthodox observance of Islam with traditional African religion. He remained attached to the traditional rites of his mothers birthplace, Sokoto. He was a man of the people rather than the elite ruling class of Muslim clerics and scholars. According to the oral tradition, he is regarded as a great military commander who carried out a strategic campaign of conquest along the Niger River. He is said to have retaliated against the Muslim leadership within Timbuktu after they failed to provide promised transport for his troops to cross the river. Islamic Chronicles The Islamic chroniclers have a different viewpoint. They portray Sonni Ali as a capricious and cruel leader. In the 16th century chronicle of Abd ar Rahmen as-Sadi, a historian based in Timbuktu, Sonni Ali is described as an impious and unscrupulous tyrant. Sonni Ali is recorded as having massacred hundreds while plundering the city of Timbuktu. This routing included killing or driving out the Tuareg and Sanhaja clerics who had acted as civil servants, teachers, and as preachers at the Sankore mosque. In later years, according to this historian, he is said to have turned on court favorites, ordering executions during temper tantrums. More Conquest Regardless of the precise interpretation of history, it is certain that Sonni Ali learned his military lessons well. Never again was he left at the mercy of someone elses fleet. He built up a river-based navy of more than 400 boats and used them to good effect in his next conquest, the trading city of Jenne (now Djennà ©). The city was placed under siege, with the fleet blockading the port. Although it took seven years for the siege to work, the city fell to Sonni Ali in 1473. The Songhai Empire now incorporated three of the greatest trading cities on the Niger: Gao, Timbuktu, and Jenne. All three had once been part of the Mali Empire. Trade Rivers formed the major trading routes within West Africa at that time.  The Songhai Empire now had effective control over the lucrative Niger River trade of gold, kola, grain, and slaves.  The cities were also part of the important trans-Saharan trade route system which brought south caravans of salt and copper, as well as goods from the Mediterranean coast. By 1476, Sonni Ali controlled the inland delta region of the Niger to the west of Timbuktu and the lakes region to the south. Regular patrols by his navy kept the trade routes open and tribute-paying kingdoms peaceful. This is an extremely fertile region of West Africa, and it became a major producer of grain under his rule. Slavery A 17th-century chronicle tells the tale of Sonni Alis slave-based farms. When he died, 12 tribes of slaves were bequeathed to his son, at least three of which had been obtained when Sonni Ali initially conquered parts of the old Mali empire. Under the Mali Empire, slaves were individually required to cultivate a measure of land and provide grain for the king. Sonni Ali changed this system and grouped the slaves into villages, each required to fulfill a common quota, with any surplus to be used by the village. Under Sonni Alis rule children born in such villages automatically became slaves. They were expected to work for the village or to be transported to the trans-Saharan markets. Sonni Ali the Warrior and Ruler Sonni Ali was brought up as part of an exclusive ruling class, a warrior horseman. The region was the best for breeding horses in Africa south of the Sahara. As such he commanded an elite cavalry, with which he was able to pacify the nomadic Tuareg to the north. With cavalry and  navy, he repulsed several attacks by the Mossi to the south, including one major attack which reached all the way to the Walata region northwest of Timbuktu. He also defeated the Fulani of the Dendi region, which was then assimilated into the Empire. Under Sonni Ali, the Songhai Empire was divided up into territories, which he placed under the rule of trusted lieutenants from his army. Traditional African cults and the observance of Islam were combined, much to the annoyance of Muslim clerics in the cities. Plots were hatched against his rule. On at least one occasion, a group of clerics and scholars at an important Muslim center were executed for treason. Death Sonni Ali died in 1492 as he returned from a punitive expedition against the Fulani.  Oral tradition claims he was poisoned by Muhammad Ture, one of his commanders. Legacy A year after Alis death, Muhammad Ture staged a coup detat against Sonni Alis son Sonni Baru and founded a new dynasty of Songhai rulers. Askiya Muhammad Ture and his descendants were strict Muslims, who reinstated orthodox observance of Islam and outlawed traditional African religions. As with his life, his legacy has two very different interpretations in the oral and Muslim traditions. In the centuries which followed his death, Muslim historians recorded Sonni Ali as The Celebrated Infidel or The Great Oppressor. Songhai oral tradition records that he was the righteous ruler of a mighty empire that encompassed more than 2,000 miles (3,200 kilometers) along the Niger River. Sources Dobler, Lavinia G, and William Allen Brown. Great Rulers of the African Past. Doubleday, 1965 Gomez, Michael A.,  African Dominion: A New History of Empire in Early and Medieval West Africa. Princeton University Press, 2018Tesfu, Julianna. â€Å"Songhai Empire (Ca. 1375-1591) BlackPast.†Ã‚  BlackPast.â€Å"The Story of Africa| BBC World Service.†Ã‚  BBC News, BBC.