473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Remove any number of spaces before and after slash

Hello everybody
I have data in Column A ..
Inside most of the cells not all I have slash
May be one slash or two or three or four

I need to remove any space before and after the slash ..
Note that the number of spaces are variable ..
Example :
Expand|Select|Wrap|Line Numbers
  1. Hello   /  Everybody            This  is /Just example/  to illustrate /         my task  .
The result should be like the following

Expand|Select|Wrap|Line Numbers
  1. Hello/Everybody            This  is/Just example/to illustrate/my task  .
Note again the spaces before and after the slash only to be removed but other spaces remain as they are

Thanks advanced
May 6 '15 #1
7 3600
Rabbit
12,516 Expert Mod 8TB
Do you know VBA? You will need to create a custom function to do this. Off the top of my head, Use the Split() function to split it on the slash, Trim() each of the indexes in the resulting array, and then recombine the array into a string.
May 6 '15 #2
Thanks Mr. Rabbit for reply
Can you provide me the code or the UDF function that enables me do that task?
May 6 '15 #3
Rabbit
12,516 Expert Mod 8TB
Sorry, we don't usually write code for people. But if you attempt it yourself and post the code here, we can help troubleshoot it for you.
May 6 '15 #4
Ok Mr. Rabbit
Sorry I'm newbie here
Here's a code I tried to modify but I failed
Expand|Select|Wrap|Line Numbers
  1. Sub RemoveSpacesBeforeAfterSlash()
  2.     Dim A, I As Long, M As Object
  3.     With Cells(1).CurrentRegion.Resize(, 1)
  4.         A = .Value
  5.         With CreateObject("VBScript.RegExp")
  6.             .Global = True
  7.             .Pattern = "*( / *)?"
  8.             For I = 1 To UBound(A, 1)
  9.                 If .test(A(I, 1)) Then A(I, 1) = _
  10.                 .Replace(A(I, 1), "/")
  11.             Next
  12.         End With
  13.         .Value = A
  14.     End With
  15. End Sub
  16.  
Regards
May 6 '15 #5
Rabbit
12,516 Expert Mod 8TB
This doesn't look anything like what I suggested. I don't see the Split function nor the Trim function I mentioned.

And I didn't say anything about using regular expressions. While regular expressions are powerful and can do what you want, they are more complicated to use than my original suggestion.
May 6 '15 #6
Luuk
1,047 Expert 1GB
Indeed, regular expressions are complicated to use.

Use use: .Pattern = "*( / *)?" (Line#7)

It start with a "*", and according to some docs the "*" means:
"Matches the preceding element zero or more times"

So, without looking any further, your regular expression is wrong! ;)
May 7 '15 #7
Well... try starting with text to columns and then joining them again...as the no of slashes can vary, you will need to create some logic to loop through.
Nov 2 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Danny | last post by:
Given this: "*" the pattern to remove the htnl code between brackets, how can I remove a series of spaces and just make one space. like here is a series of blank...
2
by: BobM | last post by:
I have two strings that I would like to compare. To guarantee the compare is not affected by trailing spaces, I would like to remove them. Will this do: MyTextBox.text.ToString().Trim()?
6
by: Paul | last post by:
Hi just wondering if there is an easy way to remove spaces in a string, tried the trim method but think it is only for leading or trailing spaces. thanks -- Paul G Software engineer.
3
by: VK | last post by:
If it was already answered somewhere, I'll be glad to be pointed to (after the necessary comments on my search abilities :-) I need as booletproof as possible way to strip out whitespaces from...
7
by: Bosconian | last post by:
I know that str.replace(/^\s+|\s+$/g,''); will trim a string of space, but what about removing extra spaces from the middle? Where "hello world"
3
kamill
by: kamill | last post by:
how can i remove blank spaces from text file......is there any function to remove a perticular chr from file...
2
by: hyperlez | last post by:
Hey all I have a column of user membership ids that is 8 characters long. These ids are based on the users surname with number added on the end to uniquely identify each user. My problem is...
1
by: buggtb | last post by:
Hi Guys, I've been given the joyous task of updating some very old scripts at work and I could do with a little help. Our Unix system dumps text files to pseudo spoolers that our windows...
2
by: SwapnilD | last post by:
I'm implementing a feature which reads comma separated txt file from server(one line at a time). Format of file is fixed, There are 3 columns on each row. After reading the row from file I...
2
by: dev saini | last post by:
how to remove number one by one in the calculator text box using JavaScript. its urgent
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.