We present density-functional-theory calculations of structural, electronic, and magnetic properties of platinum-alloy strings templated on a boron-doped single-wall carbon nanotube (6,6) model, B-SWCNT(6,6). Our calculations show that the alloy strings demonstrate strong molecular recognition, forming well-defined covalent bonds with the substrate and lead to the self-assembly of stable monatomic chains. The electronic and magnetic features of the Pt-alloy string/B-SWCNT(6,6) composite systems are mainly controlled by the presence of a magnetic alloying element (i.e., Fe, Co, and Ru). By changing the composition of the Pt alloy, the easy magnetization axis of the system can oscillate between the directions parallel and perpendicular to the tube axis. Our studies suggest that pure transition-metal (TM) or TM-alloy strings anchored on a substrate via strong molecular interactions can still possess sizable magnetic anisotropy due to spin-orbital coupling effects.