School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,134 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,022 people online right now. Registration is fast and FREE... Join Now!




Batch - Insert Character At Position In String

 

Batch - Insert Character At Position In String

Master Jake

14 Oct, 2009 - 08:21 AM
Post #1

D.I.C Head
Group Icon

Joined: 27 Feb, 2009
Posts: 106



Thanked: 6 times
Dream Kudos: 150
My Contributions
OK, so basically I need a small snippet to help me insert a character into a string. Let's take the following string for instance:

HelloWorld

I want to go to the 5th position in the string from the right and insert a space returning:

Hello World

Also, it has to work with a variable, e.g. I store the number "5" into a variable:

set posInStr=5

and then use that variable to place a character in the string at that variable's position. In total, what I'm picturing is something like this:

CODE

set myVar=HelloWorld
set posInStr=5
#:: Break String Into 2 Variables At The 5th Position Here
#:: We'll Call Them "strA" and "strB"
echo %strA% %strB%


As you can see, all I need is the code on how to harvest a string based on a variable. I know about:
%variable:~start,end%

however, I can't get it to work with a variable position, e.g.

%variable:~start,%posInStr %%

This post has been edited by Master Jake: 14 Oct, 2009 - 08:22 AM

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:47PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month